Statistiques
| Révision:

root / LicensesMercure / UFKeys.pas @ 1

Historique | Voir | Annoter | Télécharger (32,69 ko)

1
unit UFKeys;
2

    
3
interface
4

    
5
uses
6
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7
    Dialogs, PBNumEdit, StdCtrls, IdMessage, IdBaseComponent, IdComponent,
8
    IdTCPConnection, IdTCPClient, IdMessageClient, IdAttachmentFile, IdSMTP,
9
    Buttons, ExtCtrls, ComCtrls, JvExControls, JvComponent, JvLED, Spin,
10
    PBSpinEdit, IniFiles, DateUtils, mysql, IdExplicitTLSClientServerBase,
11
    IdSMTPBase, IdIMAP4, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack,
12
  IdSSL, IdSSLOpenSSL;
13

    
14
type
15
  TFKeys = class(TForm)
16
    EKey: TEdit;
17
    BBSkip: TBitBtn;
18
    BBProcess: TBitBtn;
19
    BBRemove: TBitBtn;
20
    SMTP: TIdSMTP;
21
    MReply: TIdMessage;
22
    LMail: TLabel;
23
    LCompany: TLabel;
24
    EMail: TEdit;
25
    ECompany: TEdit;
26
    GBAddress: TGroupBox;
27
    LPostalCode: TLabel;
28
    LCity: TLabel;
29
    LCountry: TLabel;
30
    EPostalCode: TEdit;
31
    ECity: TEdit;
32
    ECountry: TEdit;
33
    EAddress1: TEdit;
34
    EAddress2: TEdit;
35
    MObservations: TMemo;
36
    LFirstName: TLabel;
37
    LLastName: TLabel;
38
    LLicenseNumber: TLabel;
39
    EFirstName: TEdit;
40
    ELastName: TEdit;
41
    LFax: TLabel;
42
    EFax: TEdit;
43
    LPhone: TLabel;
44
    EPhone: TEdit;
45
    GBLicenseType: TGroupBox;
46
    RBEducation: TRadioButton;
47
    RBComplete: TRadioButton;
48
    CBValidity: TCheckBox;
49
    GBSource: TGroupBox;
50
    RBOrder: TRadioButton;
51
    RBINRA: TRadioButton;
52
    RBAjinomoto: TRadioButton;
53
    LAjinomotoNumber: TLabel;
54
    LOrderNumber: TLabel;
55
    PComplete: TPanel;
56
    EOrderNumber: TEdit;
57
    EAjinomotoNumber: TEdit;
58
    LFinalDate: TLabel;
59
    LVersion: TLabel;
60
    EVolumeSerialNumber: TEdit;
61
    LVolumeSerialNumber: TLabel;
62
    EVersion: TEdit;
63
    LSoftwareEnableKey: TLabel;
64
    ESoftwareEnableKey: TEdit;
65
    BBKeyCompute: TBitBtn;
66
    DTPFinalDate: TDateTimePicker;
67
    PAjinomotoNumber: TPanel;
68
    POrderNumber: TPanel;
69
    LEDFirstName: TJvLED;
70
    LEDLastName: TJvLED;
71
    LEDCompany: TJvLED;
72
    LEDAddress1: TJvLED;
73
    LEDAddress2: TJvLED;
74
    LEDPostalCode: TJvLED;
75
    LEDCity: TJvLED;
76
    LEDCountry: TJvLED;
77
    LEDPhone: TJvLED;
78
    LEDFax: TJvLED;
79
    LEDMail: TJvLED;
80
    LEDVersion: TJvLED;
81
    LEDVolumeSerialNumber: TJvLED;
82
    BBPrevFirstName: TBitBtn;
83
    BBNextFirstName: TBitBtn;
84
    PInformations: TPanel;
85
    LLicenseNotFound: TLabel;
86
    PLED: TPanel;
87
    PPrev: TPanel;
88
    PNext: TPanel;
89
    BBPrevLastName: TBitBtn;
90
    BBPrevCompany: TBitBtn;
91
    BBPrevAddress1: TBitBtn;
92
    BBPrevAddress2: TBitBtn;
93
    BBPrevPostalCode: TBitBtn;
94
    BBPrevCity: TBitBtn;
95
    BBPrevCountry: TBitBtn;
96
    BBPrevPhone: TBitBtn;
97
    BBPrevFax: TBitBtn;
98
    BBPrevMail: TBitBtn;
99
    BBPrevVersion: TBitBtn;
100
    BBPrevVolumeSerialNumber: TBitBtn;
101
    BBNextLastName: TBitBtn;
102
    BBNextCompany: TBitBtn;
103
    BBNextAddress1: TBitBtn;
104
    BBNextAddress2: TBitBtn;
105
    BBNextPostalCode: TBitBtn;
106
    BBNextCity: TBitBtn;
107
    BBNextCountry: TBitBtn;
108
    BBNextPhone: TBitBtn;
109
    BBNextFax: TBitBtn;
110
    BBNextMail: TBitBtn;
111
    BBNextVersion: TBitBtn;
112
    BBNextVolumeSerialNumber: TBitBtn;
113
    PBLicenseNumber: TPBSpinEdit;
114
    LCourse: TLabel;
115
    ECourse: TEdit;
116
    PEducation: TPanel;
117
    BBLock: TBitBtn;
118
    LAdmin: TLabel;
119
    IMAP4: TIdIMAP4;
120
    OpenSSL_IMAP4: TIdSSLIOHandlerSocketOpenSSL;
121
    OpenSSL_SMTP: TIdSSLIOHandlerSocketOpenSSL;
122
    procedure FormCreate(Sender: TObject);
123
    procedure FormShow(Sender: TObject);
124
    procedure BBSkipClick(Sender: TObject);
125
    procedure BBProcessClick(Sender: TObject);
126
    procedure BBRemoveClick(Sender: TObject);
127
    procedure EFirstNameChange(Sender: TObject);
128
    procedure ELastNameChange(Sender: TObject);
129
    procedure ECompanyChange(Sender: TObject);
130
    procedure EAddress1Change(Sender: TObject);
131
    procedure EAddress2Change(Sender: TObject);
132
    procedure EPostalCodeChange(Sender: TObject);
133
    procedure ECityChange(Sender: TObject);
134
    procedure ECountryChange(Sender: TObject);
135
    procedure EPhoneChange(Sender: TObject);
136
    procedure EFaxChange(Sender: TObject);
137
    procedure EMailChange(Sender: TObject);
138
    procedure EVersionChange(Sender: TObject);
139
    procedure EVolumeSerialNumberChange(Sender: TObject);
140
    procedure BBNextFirstNameClick(Sender: TObject);
141
    procedure BBNextLastNameClick(Sender: TObject);
142
    procedure BBNextCompanyClick(Sender: TObject);
143
    procedure BBNextAddress1Click(Sender: TObject);
144
    procedure BBNextAddress2Click(Sender: TObject);
145
    procedure BBNextPostalCodeClick(Sender: TObject);
146
    procedure BBNextCityClick(Sender: TObject);
147
    procedure BBNextCountryClick(Sender: TObject);
148
    procedure BBNextPhoneClick(Sender: TObject);
149
    procedure BBNextFaxClick(Sender: TObject);
150
    procedure BBNextMailClick(Sender: TObject);
151
    procedure BBNextVersionClick(Sender: TObject);
152
    procedure BBNextVolumeSerialNumberClick(Sender: TObject);
153
    procedure BBPrevFirstNameClick(Sender: TObject);
154
    procedure BBPrevLastNameClick(Sender: TObject);
155
    procedure BBPrevCompanyClick(Sender: TObject);
156
    procedure BBPrevAddress1Click(Sender: TObject);
157
    procedure BBPrevAddress2Click(Sender: TObject);
158
    procedure BBPrevPostalCodeClick(Sender: TObject);
159
    procedure BBPrevCityClick(Sender: TObject);
160
    procedure BBPrevCountryClick(Sender: TObject);
161
    procedure BBPrevPhoneClick(Sender: TObject);
162
    procedure BBPrevFaxClick(Sender: TObject);
163
    procedure BBPrevMailClick(Sender: TObject);
164
    procedure BBPrevVersionClick(Sender: TObject);
165
    procedure BBPrevVolumeSerialNumberClick(Sender: TObject);
166
    procedure BBKeyComputeClick(Sender: TObject);
167
    procedure PBLicenseNumberChange(Sender: TObject);
168
    procedure BBLockClick(Sender: TObject);
169
    procedure RBEducationClick(Sender: TObject);
170
    procedure RBCompleteClick(Sender: TObject);
171
  private
172
    { D?clarations priv?es }
173
    Key: String;
174
    Language: String;
175
    LicenseType, LicenseNumber: Integer;
176
    Version: String;
177
    FirstName, LastName, Company: String;
178
    Address1, Address2, PostalCode, City, Country: String;
179
    Phone, Fax, Mail: String;
180
    Course: String;
181
    VolumeSerialNumber, FinalDate, SoftwareEnableKey: String;
182
    Observations: AnsiString;
183
    Admin: String;
184
    procedure DisplayRequest;
185
    function IsEducation: Boolean;
186
    function IsComplete: Boolean;
187
  public
188
    { D?clarations publiques }
189
    function GetRequest: Boolean;
190
  end;
191

    
192
var
193
  FKeys: TFKeys;
194

    
195
implementation
196

    
197
uses
198
  UFMenu;
199

    
200
{$R *.dfm}
201

    
202
procedure TFKeys.FormCreate(Sender: TObject);
203
begin
204
  Top := 0;
205
  Left := 0;
206
  with IMAP4 do
207
  begin
208
    Host := IMAP_SERVER;
209
//    Username := EXCHANGE_USERNAME + '\' + EXCHANGE_SHARED_MAILBOX;
210
    Username := 'INRA\' + FMenu.EUsername.Text + '\' + EXCHANGE_SHARED_MAILBOX;
211
//    Password := EXCHANGE_PASSWORD;
212
    Password := FMenu.EPassword.Text;
213
  end;
214
  with SMTP do
215
  begin
216
    Host := SMTP_SERVER;
217
//    Username := EXCHANGE_USERNAME;
218
    Username := 'INRA\' + FMenu.EUsername.Text;
219
//    Password := EXCHANGE_PASSWORD;
220
    Password := FMenu.EPassword.Text;
221
  end;
222
end;
223

    
224
procedure TFKeys.FormShow(Sender: TObject);
225
begin
226
  PBLicenseNumber.Enabled := FMenu.TLicense.RecordCount > 0;
227
//  PBLicenseNumber.MaxValue := FMenu.TLicense.RecordCount;
228
  DisplayRequest;
229
end;
230

    
231
procedure TFKeys.BBSkipClick(Sender: TObject);
232
begin
233
  Inc(cur);
234
  if (cur < SLLicense.Count) and GetRequest
235
  then
236
    DisplayRequest
237
  else
238
    Close;
239
end;
240

    
241
procedure TFKeys.BBProcessClick(Sender: TObject);
242
var
243
  f: TIniFile;
244
  StrMessage: TStrings;
245
begin
246
  if RBEducation.Checked
247
  then
248
  begin
249
    FMenu.MLog.Lines.Add('Recording education...');
250
    with FMenu.TEducation do
251
    begin
252
      Append;
253
      FieldByName('Date').AsDateTime := Now;
254
      FieldByName('Language').AsString := Language;
255
      FieldByName('Version').AsString := EVersion.Text;
256
      FieldByName('FirstName').AsString := EFirstName.Text;
257
      FieldByName('LastName').AsString := ELastName.Text;
258
      FieldByName('Company').AsString := ECompany.Text;
259
      FieldByName('Address1').AsString := EAddress1.Text;
260
      FieldByName('Address2').AsString := EAddress2.Text;
261
      FieldByName('PostalCode').AsString := EPostalCode.Text;
262
      FieldByName('City').AsString := ECity.Text;
263
      FieldByName('Country').AsString := ECountry.Text;
264
      FieldByName('Phone').AsString := EPhone.Text;
265
      FieldByName('Fax').AsString := EFax.Text;
266
      FieldByName('Mail').AsString := EMail.Text;
267
      FieldByName('Course').AsString := ECourse.Text;
268
      FieldByName('VolumeSerialNumber').AsString := EVolumeSerialNumber.Text;
269
      FieldByName('FinalDate').AsDateTime := DTPFinalDate.DateTime;
270
      FieldByName('SoftwareEnableKey').AsString := ESoftwareEnableKey.Text;
271
      Post;
272
    end;
273
  end;
274
  if RBComplete.Checked
275
  then
276
  begin
277
    FMenu.MLog.Lines.Add('Updating license...');
278
    with FMenu.TLicense do
279
    begin
280
      Edit;
281
      FieldByName('Language').AsString := Language;
282
      FieldByName('Version').AsString := EVersion.Text;
283
      FieldByName('FirstName').AsString := EFirstName.Text;
284
      FieldByName('LastName').AsString := ELastName.Text;
285
      FieldByName('Company').AsString := ECompany.Text;
286
      FieldByName('Address1').AsString := EAddress1.Text;
287
      FieldByName('Address2').AsString := EAddress2.Text;
288
      FieldByName('PostalCode').AsString := EPostalCode.Text;
289
      FieldByName('City').AsString := ECity.Text;
290
      FieldByName('Country').AsString := ECountry.Text;
291
      FieldByName('Phone').AsString := EPhone.Text;
292
      FieldByName('Fax').AsString := EFax.Text;
293
      FieldByName('Mail').AsString := EMail.Text;
294
      FieldByName('VolumeSerialNumber').AsString := EVolumeSerialNumber.Text;
295
      FieldByName('FinalDate').AsDateTime := DTPFinalDate.DateTime;
296
      FieldByName('SoftwareEnableKey').AsString := ESoftwareEnableKey.Text;
297
      Post;
298
    end;
299
  end;
300
  try
301
    f := TIniFile.Create(SHARED_DRIVE + SHARED_FOLDER + 'Fichiers\InraPorc.lic');
302
    f.WriteInteger ('License', 'LicenseType', LicenseType);
303
    f.WriteInteger ('License', 'LicenseNumber', PBLicenseNumber.Value) ;
304
    f.WriteString ('License', 'Version', EVersion.Text);
305
    f.WriteString ('License', 'FirstName', EFirstName.Text);
306
    f.WriteString ('License', 'LastName', ELastName.Text);
307
    f.WriteString ('License', 'Company', ECompany.Text);
308
    f.WriteString ('License', 'Address1', EAddress1.Text);
309
    f.WriteString ('License', 'Address2', EAddress2.Text);
310
    f.WriteString ('License', 'PostalCode', EPostalCode.Text);
311
    f.WriteString ('License', 'City', ECity.Text);
312
    f.WriteString ('License', 'Country', ECountry.Text);
313
    f.WriteString ('License', 'Phone', EPhone.Text);
314
    f.WriteString ('License', 'Fax', EFax.Text);
315
    f.WriteString ('License', 'Mail', EMail.Text);
316
    f.WriteString ('License', 'Course', ECourse.Text);
317
    f.WriteString ('License', 'VolumeSerialNumber', EVolumeSerialNumber.Text);
318
    f.WriteString ('License', 'FinalDate', DateToStr(DTPFinalDate.Date));
319
    f.WriteString ('License', 'SoftwareEnableKey', ESoftwareEnableKey.Text);
320
    f.Free;
321
    FMenu.MLog.Lines.Add('Mailing to ' + EMail.Text + '...');
322
    with MReply do
323
    begin
324
      Body.Clear;
325
      MessageParts.Clear;
326
      From.Name := 'InraPorc';
327
      From.Address := MAIL_INRAPORC;
328
      Recipients.EMailAddresses := EMail.Text;
329
      StrMessage := TStringList.Create;
330
      if Language = 'FR'
331
      then // R?ponse (fran?ais)
332
      begin
333
        if RBEducation.Checked
334
        then
335
          Subject := '[InraPorc] Cl? d''activation pour licence ?ducation';
336
        if RBComplete.Checked
337
        then
338
          Subject := Format('[InraPorc] Cl? d''activation pour licence num?ro %d', [PBLicenseNumber.Value]);
339
        StrMessage.LoadFromFile(SHARED_DRIVE + SHARED_FOLDER + 'Messages\Cl?_FR.txt');
340
        Body.AddStrings(StrMessage);
341
        if RBEducation.Checked
342
        then
343
          Body.Add('L''utilisation gratuite de ce logiciel est strictement r?serv?e ? l''enseignement.');
344
        Body.Add(Format('La cl? d''activation est valable jusqu''au %s.', [DateToStr(DTPFinalDate.Date)]));
345
        if RBComplete.Checked
346
        then
347
          if CBValidity.Checked
348
          then
349
            Body.Add('Un nouveau fichier de licence vous sera automatiquement envoy? avant la date d''expiration.')
350
          else
351
            if RBOrder.Checked
352
            then
353
              Body.Add('Suite au r?glement de la facture, un nouveau fichier de licence vous sera envoy?.')
354
            else
355
              Body.Add('Suite ? la signature des contrats, un nouveau fichier de licence vous sera envoy?.');
356
        Body.Add('');
357
        StrMessage.LoadFromFile(SHARED_DRIVE + SHARED_FOLDER + 'Messages\Signature_FR.txt');
358
        Body.AddStrings(StrMessage);
359
      end
360
      else // Reply (english)
361
      begin
362
        if RBEducation.Checked
363
        then
364
          Subject := '[InraPorc] License activation key for educational license';
365
        if RBComplete.Checked
366
        then
367
          Subject := Format('[InraPorc] License activation key for license number %d', [PBLicenseNumber.Value]);
368
        StrMessage.LoadFromFile(SHARED_DRIVE + SHARED_FOLDER + 'Messages\Cl?_EN.txt');
369
        Body.AddStrings(StrMessage);
370
        if RBEducation.Checked
371
        then
372
          Body.Add('The use of this license is strictly reserved to educational organizations.');
373
        Body.Add(Format('The license activation key is valid until %s.', [DateToStr(DTPFinalDate.Date)]));
374
        if RBComplete.Checked
375
        then
376
          if CBValidity.Checked
377
          then
378
            Body.Add('You will automatically receive a new license file before the expiration date.')
379
          else
380
            if RBOrder.Checked
381
            then
382
              Body.Add('After receiving your payment, we will send you a new license file.')
383
            else
384
              Body.Add('After receiving the signed contracts, we will send you a new license file.');
385
        Body.Add('');
386
        StrMessage.LoadFromFile(SHARED_DRIVE + SHARED_FOLDER + 'Messages\Signature_EN.txt');
387
        Body.AddStrings(StrMessage);
388
      end;
389
      StrMessage.Free;
390
      if FileExists(SHARED_DRIVE + SHARED_FOLDER + 'Fichiers\InraPorc.lic')
391
      then
392
        TIdAttachmentFile.Create(MessageParts, SHARED_DRIVE + SHARED_FOLDER + '\Fichiers\InraPorc.lic')
393
      else
394
        FMenu.MLog.Lines.Add('File Fichiers\InraPorc.lic not found!');
395
    end;
396
    FMenu.MLog.Lines.Add('SMTP...');
397
    try
398
      SMTP.Connect;
399
      try
400
        SMTP.Send(MReply);
401
      finally
402
        SMTP.Disconnect;
403
        if IMAP4.Connect
404
        then
405
          try
406
            if not IMAP4.AppendMsg('?l?ments envoy?s', MReply, MReply.LastGeneratedHeaders)
407
            then
408
              FMenu.MLog.Lines.Add('Message could not be copied in IMAP server!');
409
          finally
410
            IMAP4.Disconnect;
411
            if not DeleteFile(SHARED_DRIVE + SHARED_FOLDER + 'Fichiers\InraPorc.lic')
412
            then
413
              FMenu.MLog.Lines.Add('File Fichiers\InraPorc.lic could not be deleted!');
414
            BBRemoveClick(nil);
415
          end
416
        else
417
          FMenu.MLog.Lines.Add('IMAP server could not be connected!');
418
      end;
419
    except
420
      FMenu.MLog.Lines.Add('Message could not be sent!');
421
    end;
422
  except
423
    FMenu.MLog.Lines.Add('File Fichiers\InraPorc.lic could not be created!');
424
  end;
425
end;
426

    
427
procedure TFKeys.BBRemoveClick(Sender: TObject);
428
begin
429
  FMenu.MLog.Lines.Add('Logging record...');
430
  with FMenu.TLicenses do
431
  begin
432
    Append;
433
    FieldByName('Date').AsDateTime := Now;
434
    FieldByName('Admin').AsString := FMenu.EAdmin.Text;
435
    FieldByName('Key').AsString := Key;
436
    FieldByName('Language').AsString := Language;
437
    FieldByName('LicenseType').AsInteger := LicenseType;
438
    FieldByName('LicenseNumber').AsInteger := LicenseNumber;
439
    FieldByName('Version').AsString := Version;
440
    FieldByName('FirstName').AsString := FirstName;
441
    FieldByName('LastName').AsString := LastName;
442
    FieldByName('Company').AsString := Company;
443
    FieldByName('Address1').AsString := Address1;
444
    FieldByName('Address2').AsString := Address2;
445
    FieldByName('PostalCode').AsString := PostalCode;
446
    FieldByName('City').AsString := City;
447
    FieldByName('Country').AsString := Country;
448
    FieldByName('Phone').AsString := Phone;
449
    FieldByName('Fax').AsString := Fax;
450
    FieldByName('Mail').AsString := Mail;
451
    FieldByName('Course').AsString := Course;
452
    FieldByName('VolumeSerialNumber').AsString := VolumeSerialNumber;
453
    FieldByName('FinalDate').AsString := FinalDate;
454
    FieldByName('SoftwareEnableKey').AsString := SoftwareEnableKey;
455
    FieldByName('Observations').AsVariant := Observations;
456
    Post;
457
  end;
458
  que := 'DELETE FROM `licences` where `Key` = ''' + SLLicense[cur] + '''';
459
  FMenu.MLog.Lines.Add(que);
460
  if mysql_query(con, PAnsiChar(que)) <> 0
461
  then
462
    FMenu.MLog.Lines.Add(mysql_error(con))
463
  else
464
  begin
465
    SLLicense.Delete(cur);
466
    FMenu.PBKeys.AsInteger := FMenu.PBKeys.AsInteger - 1;
467
    Dec(cur);
468
  end;
469
  BBSkipClick(nil);
470
end;
471

    
472
procedure TFKeys.BBLockClick(Sender: TObject);
473
begin
474
  que := 'UPDATE `licences` SET `Admin` = ''' + FMenu.EAdmin.Text + ''' WHERE `Key` = ''' + SLLicense[cur] + '''';
475
  FMenu.MLog.Lines.Add(que);
476
  if mysql_query(con, PAnsiChar(que)) <> 0
477
  then
478
    FMenu.MLog.Lines.Add(mysql_error(con))
479
  else
480
  begin
481
    LAdmin.Caption := 'Dossier pris en charge par ' + FMenu.EAdmin.Text;
482
    LAdmin.Visible := True;
483
  end;
484
end;
485

    
486
function TFKeys.GetRequest: Boolean;
487
begin
488
  Result := False;
489
  que := 'SELECT * FROM `licences` where `Key` = ''' + SLLicense[cur] + '''';
490
  FMenu.MLog.Lines.Add(que);
491
  if mysql_query(con, PAnsiChar(que)) <> 0
492
  then
493
    FMenu.MLog.Lines.Add(mysql_error(con))
494
  else
495
  begin
496
    res := mysql_store_result(con);
497
    if res = nil
498
    then
499
      FMenu.MLog.Lines.Add(mysql_error(con))
500
    else
501
    begin
502
      row := mysql_fetch_row(res);
503
      if row = nil
504
      then
505
        FMenu.MLog.Lines.Add(mysql_error(con))
506
      else
507
      begin
508
        Key := row^[0];
509
        Language := row^[1];
510
        LicenseType := StrToInt(row^[2]);
511
        LicenseNumber := StrToInt(row^[3]);
512
        Version := row^[4];
513
        FirstName := row^[5];
514
        LastName := row^[6];
515
        Company := row^[7];
516
        Address1 := row^[8];
517
        Address2 := row^[9];
518
        PostalCode := row^[10];
519
        City := row^[11];
520
        Country := row^[12];
521
        Phone := row^[13];
522
        Fax := row^[14];
523
        Mail := row^[15];
524
        Course := row^[16];
525
        VolumeSerialNumber := row^[17];
526
        FinalDate := row^[18];
527
        SoftwareEnableKey := row^[19];
528
        Observations := row^[20];
529
        Admin := row^[21];
530
        Result := True;
531
      end;
532
      mysql_free_result(res);
533
    end;
534
  end;
535
end;
536

    
537
procedure TFKeys.DisplayRequest;
538
begin
539
  EKey.Text := Key;
540
  RBEducation.Checked := LicenseType = 1;
541
  RBComplete.Checked := LicenseType = 2;
542
  ECourse.Text := Course;
543
  if PBLicenseNumber.Value = LicenseNumber
544
  then
545
    PBLicenseNumberChange(nil)
546
  else
547
    PBLicenseNumber.Value := LicenseNumber;
548
  ESoftwareEnableKey.Text := SoftwareEnableKey;
549
  BBNextFirstNameClick(nil);
550
  BBNextLastNameClick(nil);
551
  BBNextCompanyClick(nil);
552
  BBNextAddress1Click(nil);
553
  BBNextAddress2Click(nil);
554
  BBNextPostalCodeClick(nil);
555
  BBNextCityClick(nil);
556
  BBNextCountryClick(nil);
557
  BBNextPhoneClick(nil);
558
  BBNextFaxClick(nil);
559
  BBNextMailClick(nil);
560
  BBNextVersionClick(nil);
561
  BBNextVolumeSerialNumberClick(nil);
562
  MObservations.Text := Observations;
563
  LAdmin.Caption := 'Dossier pris en charge par ' + Admin;
564
  LAdmin.Visible := (Admin <> '');
565
  BBLock.Enabled := not LAdmin.Visible;
566
  BBRemove.Enabled := BBLock.Enabled or (Admin = FMenu.EAdmin.Text);
567
  GBLicenseType.Enabled := BBRemove.Enabled;
568
end;
569

    
570
procedure TFKeys.RBCompleteClick(Sender: TObject);
571
begin
572
  PEducation.Visible := False;
573
  PComplete.Visible := True;
574
  LicenseType := 2;
575
  PBLicenseNumberChange(nil);
576
end;
577

    
578
procedure TFKeys.RBEducationClick(Sender: TObject);
579
begin
580
  PEducation.Visible := True;
581
  PComplete.Visible := False;
582
  LicenseType := 1;
583
  PBLicenseNumberChange(nil);
584
end;
585

    
586
procedure TFKeys.PBLicenseNumberChange(Sender: TObject);
587
begin
588
  LLicenseNotFound.Visible := not (RBComplete.Checked and FMenu.TLicense.FindKey([PBLicenseNumber.Value]));
589
  if LLicenseNotFound.Visible
590
  then
591
    PBLicenseNumber.Font.Color := clRed
592
  else
593
    PBLicenseNumber.Font.Color := clWindowText;
594
  CBValidity.Visible := not LLicenseNotFound.Visible;
595
  GBSource.Visible := not LLicenseNotFound.Visible;
596
  if not LLicenseNotFound.Visible
597
  then
598
    with FMenu.TLicense do
599
    begin
600
      CBValidity.Checked := FieldByName('Validity').AsBoolean;
601
      RBOrder.Checked := FieldByName('Type').AsInteger = 0;
602
      POrderNumber.Visible := RBOrder.Checked;
603
      EOrderNumber.Text := FieldByName('Source').AsString;
604
      RBINRA.Checked := FieldByName('Type').AsInteger = 1;
605
      RBAjinomoto.Checked := FieldByName('Type').AsInteger = 2;
606
      PAjinomotoNumber.Visible := RBAjinomoto.Checked;
607
      EAjinomotoNumber.Text := FieldByName('Source').AsString;
608
      LEDFirstName.Status := FieldByName('FirstName').IsNull or (FirstName = FieldByName('FirstName').AsString);
609
      LEDLastName.Status := FieldByName('LastName').IsNull or (LastName = FieldByName('LastName').AsString);
610
      LEDCompany.Status := FieldByName('Company').IsNull or (Company = FieldByName('Company').AsString);
611
      LEDAddress1.Status := FieldByName('Address1').IsNull or (Address1 = FieldByName('Address1').AsString);
612
      LEDAddress2.Status := FieldByName('Address2').IsNull or (Address2 = FieldByName('Address2').AsString);
613
      LEDPostalCode.Status := FieldByName('PostalCode').IsNull or (PostalCode = FieldByName('PostalCode').AsString);
614
      LEDCity.Status := FieldByName('City').IsNull or (City = FieldByName('City').AsString);
615
      LEDCountry.Status := FieldByName('Country').IsNull or (Country = FieldByName('Country').AsString);
616
      LEDPhone.Status := FieldByName('Phone').IsNull or (Phone = FieldByName('Phone').AsString);
617
      LEDFax.Status := FieldByName('Fax').IsNull or (Fax = FieldByName('Fax').AsString);
618
      LEDMail.Status := FieldByName('Mail').IsNull or (Mail = FieldByName('Mail').AsString);
619
      LEDVersion.Status := FieldByName('Version').IsNull or (Version = FieldByName('Version').AsString);
620
      LEDVolumeSerialNumber.Status := FieldByName('VolumeSerialNumber').IsNull or (VolumeSerialNumber = FieldByName('VolumeSerialNumber').AsString);
621
    end;
622
  PInformations.Enabled := (RBEducation.Checked or (RBComplete.Checked and not LLicenseNotFound.Visible)) and BBRemove.Enabled;
623
  PLED.Visible := RBComplete.Checked and not LLicenseNotFound.Visible;
624
  PPrev.Visible := RBComplete.Checked and not LLicenseNotFound.Visible;
625
  PNext.Visible := RBEducation.Checked or (RBComplete.Checked and not LLicenseNotFound.Visible);
626
  if not (RBEducation.Checked or (RBComplete.Checked and not LLicenseNotFound.Visible))
627
  then
628
    DTPFinalDate.DateTime := Date;
629
  if RBComplete.Checked and not LLicenseNotFound.Visible and not CBValidity.Checked
630
  then
631
    DTPFinalDate.DateTime := FMenu.TLicense.FieldByName('FinalDate').AsDateTime;
632
  if RBEducation.Checked or (RBComplete.Checked and not LLicenseNotFound.Visible and CBValidity.Checked)
633
  then
634
    DTPFinalDate.DateTime := FMenu.DateLimite;
635
  if BBNextFirstName.Enabled
636
  then
637
    BBNextFirstNameClick(nil)
638
  else
639
    EFirstNameChange(nil);
640
  if BBNextLastName.Enabled
641
  then
642
    BBNextLastNameClick(nil)
643
  else
644
    ELastNameChange(nil);
645
  if BBNextCompany.Enabled
646
  then
647
    BBNextCompanyClick(nil)
648
  else
649
    ECompanyChange(nil);
650
  if BBNextAddress1.Enabled
651
  then
652
    BBNextAddress1Click(nil)
653
  else
654
    EAddress1Change(nil);
655
  if BBNextAddress2.Enabled
656
  then
657
    BBNextAddress2Click(nil)
658
  else
659
    EAddress2Change(nil);
660
  if BBNextPostalCode.Enabled
661
  then
662
    BBNextPostalCodeClick(nil)
663
  else
664
    EPostalCodeChange(nil);
665
  if BBNextCity.Enabled
666
  then
667
    BBNextCityClick(nil)
668
  else
669
    ECityChange(nil);
670
  if BBNextCountry.Enabled
671
  then
672
    BBNextCountryClick(nil)
673
  else
674
    ECountryChange(nil);
675
  if BBNextPhone.Enabled
676
  then
677
    BBNextPhoneClick(nil)
678
  else
679
    EPhoneChange(nil);
680
  if BBNextFax.Enabled
681
  then
682
    BBNextFaxClick(nil)
683
  else
684
    EFaxChange(nil);
685
  if BBNextMail.Enabled
686
  then
687
    BBNextMailClick(nil)
688
  else
689
    EMailChange(nil);
690
  if BBNextVersion.Enabled
691
  then
692
    BBNextVersionClick(nil)
693
  else
694
    EVersionChange(nil);
695
  if BBNextVolumeSerialNumber.Enabled
696
  then
697
    BBNextVolumeSerialNumberClick(nil)
698
  else
699
    EVolumeSerialNumberChange(nil);
700
end;
701

    
702
procedure TFKeys.EFirstNameChange(Sender: TObject);
703
begin
704
  BBNextFirstName.Enabled := EFirstName.Text <> FirstName;
705
  if PPrev.Visible
706
  then
707
    BBPrevFirstName.Enabled := EFirstName.Text <> FMenu.TLicense.FieldByName('FirstName').AsString;
708
  BBProcess.Enabled := (IsEducation or (IsComplete and not LLicenseNotFound.Visible)) and BBRemove.Enabled;
709
end;
710

    
711
procedure TFKeys.ELastNameChange(Sender: TObject);
712
begin
713
  BBNextLastName.Enabled := ELastName.Text <> LastName;
714
  if PPrev.Visible
715
  then
716
    BBPrevLastName.Enabled := ELastName.Text <> FMenu.TLicense.FieldByName('LastName').AsString;
717
  BBProcess.Enabled := (IsEducation or (IsComplete and not LLicenseNotFound.Visible)) and BBRemove.Enabled;
718
end;
719

    
720
procedure TFKeys.ECompanyChange(Sender: TObject);
721
begin
722
  BBNextCompany.Enabled := ECompany.Text <> Company;
723
  if PPrev.Visible
724
  then
725
    BBPrevCompany.Enabled := ECompany.Text <> FMenu.TLicense.FieldByName('Company').AsString;
726
  BBProcess.Enabled := (IsEducation or (IsComplete and not LLicenseNotFound.Visible)) and BBRemove.Enabled;
727
end;
728

    
729
procedure TFKeys.EAddress1Change(Sender: TObject);
730
begin
731
  BBNextAddress1.Enabled := EAddress1.Text <> Address1;
732
  if PPrev.Visible
733
  then
734
    BBPrevAddress1.Enabled := EAddress1.Text <> FMenu.TLicense.FieldByName('Address1').AsString;
735
end;
736

    
737
procedure TFKeys.EAddress2Change(Sender: TObject);
738
begin
739
  BBNextAddress2.Enabled := EAddress2.Text <> Address2;
740
  if PPrev.Visible
741
  then
742
    BBPrevAddress2.Enabled := EAddress2.Text <> FMenu.TLicense.FieldByName('Address2').AsString;
743
end;
744

    
745
procedure TFKeys.EPostalCodeChange(Sender: TObject);
746
begin
747
  BBNextPostalCode.Enabled := EPostalCode.Text <> PostalCode;
748
  if PPrev.Visible
749
  then
750
    BBPrevPostalCode.Enabled := EPostalCode.Text <> FMenu.TLicense.FieldByName('PostalCode').AsString;
751
end;
752

    
753
procedure TFKeys.ECityChange(Sender: TObject);
754
begin
755
  BBNextCity.Enabled := ECity.Text <> City;
756
  if PPrev.Visible
757
  then
758
    BBPrevCity.Enabled := ECity.Text <> FMenu.TLicense.FieldByName('City').AsString;
759
end;
760

    
761
procedure TFKeys.ECountryChange(Sender: TObject);
762
begin
763
  BBNextCountry.Enabled := ECountry.Text <> Country;
764
  if PPrev.Visible
765
  then
766
    BBPrevCountry.Enabled := ECountry.Text <> FMenu.TLicense.FieldByName('Country').AsString;
767
end;
768

    
769
procedure TFKeys.EPhoneChange(Sender: TObject);
770
begin
771
  BBNextPhone.Enabled := EPhone.Text <> Phone;
772
  if PPrev.Visible
773
  then
774
    BBPrevPhone.Enabled := EPhone.Text <> FMenu.TLicense.FieldByName('Phone').AsString;
775
end;
776

    
777
procedure TFKeys.EFaxChange(Sender: TObject);
778
begin
779
  BBNextFax.Enabled := EFax.Text <> Fax;
780
  if PPrev.Visible
781
  then
782
    BBPrevFax.Enabled := EFax.Text <> FMenu.TLicense.FieldByName('Fax').AsString;
783
end;
784

    
785
procedure TFKeys.EMailChange(Sender: TObject);
786
begin
787
  BBNextMail.Enabled := EMail.Text <> Mail;
788
  if PPrev.Visible
789
  then
790
    BBPrevMail.Enabled := EMail.Text <> FMenu.TLicense.FieldByName('Mail').AsString;
791
end;
792

    
793
procedure TFKeys.EVersionChange(Sender: TObject);
794
begin
795
  BBNextVersion.Enabled := EVersion.Text <> Version;
796
  if PPrev.Visible
797
  then
798
    BBPrevVersion.Enabled := EVersion.Text <> FMenu.TLicense.FieldByName('Version').AsString;
799
  BBProcess.Enabled := (IsEducation or (IsComplete and not LLicenseNotFound.Visible)) and BBRemove.Enabled;
800
end;
801

    
802
procedure TFKeys.EVolumeSerialNumberChange(Sender: TObject);
803
begin
804
  BBNextVolumeSerialNumber.Enabled := EVolumeSerialNumber.Text <> VolumeSerialNumber;
805
  if PPrev.Visible
806
  then
807
    BBPrevVolumeSerialNumber.Enabled := EVolumeSerialNumber.Text <> FMenu.TLicense.FieldByName('VolumeSerialNumber').AsString;
808
  BBProcess.Enabled := (IsEducation or (IsComplete and not LLicenseNotFound.Visible)) and BBRemove.Enabled;
809
end;
810

    
811
procedure TFKeys.BBNextFirstNameClick(Sender: TObject);
812
begin
813
  EFirstName.Text := FirstName;
814
end;
815

    
816
procedure TFKeys.BBNextLastNameClick(Sender: TObject);
817
begin
818
  ELastName.Text := LastName;
819
end;
820

    
821
procedure TFKeys.BBNextCompanyClick(Sender: TObject);
822
begin
823
  ECompany.Text := Company;
824
end;
825

    
826
procedure TFKeys.BBNextAddress1Click(Sender: TObject);
827
begin
828
  EAddress1.Text := Address1;
829
end;
830

    
831
procedure TFKeys.BBNextAddress2Click(Sender: TObject);
832
begin
833
  EAddress2.Text := Address2;
834
end;
835

    
836
procedure TFKeys.BBNextPostalCodeClick(Sender: TObject);
837
begin
838
  EPostalCode.Text := PostalCode;
839
end;
840

    
841
procedure TFKeys.BBNextCityClick(Sender: TObject);
842
begin
843
  ECity.Text := City;
844
end;
845

    
846
procedure TFKeys.BBNextCountryClick(Sender: TObject);
847
begin
848
  ECountry.Text := Country;
849
end;
850

    
851
procedure TFKeys.BBNextPhoneClick(Sender: TObject);
852
begin
853
  EPhone.Text := Phone;
854
end;
855

    
856
procedure TFKeys.BBNextFaxClick(Sender: TObject);
857
begin
858
  EFax.Text := Fax;
859
end;
860

    
861
procedure TFKeys.BBNextMailClick(Sender: TObject);
862
begin
863
  EMail.Text := Mail;
864
end;
865

    
866
procedure TFKeys.BBNextVersionClick(Sender: TObject);
867
begin
868
  EVersion.Text := Version;
869
end;
870

    
871
procedure TFKeys.BBNextVolumeSerialNumberClick(Sender: TObject);
872
begin
873
  EVolumeSerialNumber.Text := VolumeSerialNumber;
874
end;
875

    
876
procedure TFKeys.BBPrevFirstNameClick(Sender: TObject);
877
begin
878
  EFirstName.Text := FMenu.TLicense.FieldByName('FirstName').AsString;
879
end;
880

    
881
procedure TFKeys.BBPrevLastNameClick(Sender: TObject);
882
begin
883
  ELastName.Text := FMenu.TLicense.FieldByName('LastName').AsString;
884
end;
885

    
886
procedure TFKeys.BBPrevCompanyClick(Sender: TObject);
887
begin
888
  ECompany.Text := FMenu.TLicense.FieldByName('Company').AsString;
889
end;
890

    
891
procedure TFKeys.BBPrevAddress1Click(Sender: TObject);
892
begin
893
  EAddress1.Text := FMenu.TLicense.FieldByName('Address1').AsString;
894
end;
895

    
896
procedure TFKeys.BBPrevAddress2Click(Sender: TObject);
897
begin
898
  EAddress2.Text := FMenu.TLicense.FieldByName('Address2').AsString;
899
end;
900

    
901
procedure TFKeys.BBPrevPostalCodeClick(Sender: TObject);
902
begin
903
  EPostalCode.Text := FMenu.TLicense.FieldByName('PostalCode').AsString;
904
end;
905

    
906
procedure TFKeys.BBPrevCityClick(Sender: TObject);
907
begin
908
  ECity.Text := FMenu.TLicense.FieldByName('City').AsString;
909
end;
910

    
911
procedure TFKeys.BBPrevCountryClick(Sender: TObject);
912
begin
913
  ECountry.Text := FMenu.TLicense.FieldByName('Country').AsString;
914
end;
915

    
916
procedure TFKeys.BBPrevPhoneClick(Sender: TObject);
917
begin
918
  EPhone.Text := FMenu.TLicense.FieldByName('Phone').AsString;
919
end;
920

    
921
procedure TFKeys.BBPrevFaxClick(Sender: TObject);
922
begin
923
  EFax.Text := FMenu.TLicense.FieldByName('Fax').AsString;
924
end;
925

    
926
procedure TFKeys.BBPrevMailClick(Sender: TObject);
927
begin
928
  EMail.Text := FMenu.TLicense.FieldByName('Mail').AsString;
929
end;
930

    
931
procedure TFKeys.BBPrevVersionClick(Sender: TObject);
932
begin
933
  EVersion.Text := FMenu.TLicense.FieldByName('Version').AsString;
934
end;
935

    
936
procedure TFKeys.BBPrevVolumeSerialNumberClick(Sender: TObject);
937
begin
938
  EVolumeSerialNumber.Text := FMenu.TLicense.FieldByName('VolumeSerialNumber').AsString;
939
end;
940

    
941
procedure TFKeys.BBKeyComputeClick(Sender: TObject);
942
begin
943
  if RBEducation.Checked
944
  then
945
    ESoftwareEnableKey.Text := FMenu.EducationKey(EVersion.Text, EFirstName.Text, ELastName.Text, ECompany.Text, EVolumeSerialNumber.Text, DateToStr(DTPFinalDate.Date));
946
  if RBComplete.Checked
947
  then
948
    ESoftwareEnableKey.Text := FMenu.CompleteKey(PBLicenseNumber.Value, EVersion.Text, EFirstName.Text, ELastName.Text, ECompany.Text, EVolumeSerialNumber.Text, DateToStr(DTPFinalDate.Date));
949
  BBProcess.Enabled := (IsEducation or (IsComplete and not LLicenseNotFound.Visible)) and BBRemove.Enabled;
950
end;
951

    
952
function TFKeys.IsEducation: Boolean;
953
begin
954
  Result := RBEducation.Checked
955
    and (Length(EVersion.Text) > 0)
956
    and (Length(EVolumeSerialNumber.Text) > 0)
957
    and (Length(EFirstName.Text) > 0)
958
    and (Length(ELastName.Text) > 0)
959
    and (Length(ECompany.Text) > 0)
960
    and (AnsiSameText(ESoftwareEnableKey.Text, FMenu.EducationKey(EVersion.Text, EFirstName.Text, ELastName.Text, ECompany.Text, EVolumeSerialNumber.Text, DateToStr(DTPFinalDate.Date))));
961
end;
962

    
963
function TFKeys.IsComplete: Boolean;
964
begin
965
  Result := RBComplete.Checked
966
    and (PBLicenseNumber.Value > 0)
967
    and (Length(EVersion.Text) > 0)
968
    and (Length(EVolumeSerialNumber.Text) > 0)
969
    and (Length(EFirstName.Text) > 0)
970
    and (Length(ELastName.Text) > 0)
971
    and (AnsiSameText(ESoftwareEnableKey.Text, FMenu.CompleteKey(PBLicenseNumber.Value, EVersion.Text, EFirstName.Text, ELastName.Text, ECompany.Text, EVolumeSerialNumber.Text, DateToStr(DTPFinalDate.Date))));
972
end;
973

    
974
end.