Statistiques
| Révision:

root / LicensesMercure / UFManual.pas @ 4

Historique | Voir | Annoter | Télécharger (17,933 ko)

1
unit UFManual;
2

    
3
interface
4

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

    
13
type
14
  TFManual = class(TForm)
15
    LLicenseNumber: TLabel;
16
    GBSource: TGroupBox;
17
    RBOrder: TRadioButton;
18
    RBINRA: TRadioButton;
19
    RBAjinomoto: TRadioButton;
20
    POrderNumber: TPanel;
21
    LOrderNumber: TLabel;
22
    EOrderNumber: TEdit;
23
    PAjinomotoNumber: TPanel;
24
    LAjinomotoNumber: TLabel;
25
    EAjinomotoNumber: TEdit;
26
    CBValidity: TCheckBox;
27
    PBLicenseNumber: TPBSpinEdit;
28
    LCompany: TLabel;
29
    LFirstName: TLabel;
30
    LLastName: TLabel;
31
    ECompany: TEdit;
32
    EFirstName: TEdit;
33
    ELastName: TEdit;
34
    LMail: TLabel;
35
    EMail: TEdit;
36
    LFinalDate: TLabel;
37
    LSoftwareEnableKey: TLabel;
38
    ESoftwareEnableKey: TEdit;
39
    BBKeyCompute: TBitBtn;
40
    DTPFinalDate: TDateTimePicker;
41
    BBSend: TBitBtn;
42
    BBSave: TBitBtn;
43
    PInfo: TPanel;
44
    LLicenseNotFound: TLabel;
45
    SMTP: TIdSMTP;
46
    MKey: TIdMessage;
47
    MFile: TMemo;
48
    IMAP4: TIdIMAP4;
49
    OpenSSL_IMAP4: TIdSSLIOHandlerSocketOpenSSL;
50
    OpenSSL_SMTP: TIdSSLIOHandlerSocketOpenSSL;
51
    procedure FormCreate(Sender: TObject);
52
    procedure FormShow(Sender: TObject);
53
    procedure PBLicenseNumberChange(Sender: TObject);
54
    procedure BBKeyComputeClick(Sender: TObject);
55
    procedure BBSendClick(Sender: TObject);
56
    procedure BBSaveClick(Sender: TObject);
57
    procedure EInfoChange(Sender: TObject);
58
  private
59
    { D?clarations priv?es }
60
  public
61
    { D?clarations publiques }
62
  end;
63

    
64
var
65
  FManual: TFManual;
66

    
67
implementation
68

    
69
uses
70
  UFMenu;
71

    
72
{$R *.dfm}
73

    
74
procedure TFManual.FormCreate(Sender: TObject);
75
begin
76
  Top := 0;
77
  Left := 0;
78
  with IMAP4 do
79
  begin
80
    Host := IMAP_SERVER;
81
//    Username := EXCHANGE_USERNAME + '\' + EXCHANGE_SHARED_MAILBOX;
82
    Username := 'INRA\' + FMenu.EUsername.Text + '\' + EXCHANGE_SHARED_MAILBOX;
83
//    Password := EXCHANGE_PASSWORD;
84
    Password := FMenu.EPassword.Text;
85
  end;
86
  with SMTP do
87
  begin
88
    Host := SMTP_SERVER;
89
//    Username := EXCHANGE_USERNAME;
90
    Username := 'INRA\' + FMenu.EUsername.Text;
91
//    Password := EXCHANGE_PASSWORD;
92
    Password := FMenu.EPassword.Text;
93
  end;
94
end;
95

    
96
procedure TFManual.FormShow(Sender: TObject);
97
begin
98
  if FMenu.TLicense.RecordCount > 0
99
  then
100
  begin
101
    PBLicenseNumber.MaxValue := FMenu.TLicense.RecordCount;
102
    PBLicenseNumber.MinValue := 1;
103
    PBLicenseNumber.Value := PBLicenseNumber.MinValue;
104
//    PBLicenseNumberChange(nil);
105
  end
106
  else
107
    PBLicenseNumber.Enabled := FALSE;
108
end;
109

    
110
procedure TFManual.PBLicenseNumberChange(Sender: TObject);
111
begin
112
  if FMenu.TLicense.FindKey([PBLicenseNumber.Value])
113
  then // Affichage des informations
114
  begin
115
    PInfo.Visible := TRUE;
116
    CBValidity.Visible := TRUE;
117
    LLicenseNotFound.Visible := FALSE;
118
    with FMenu.TLicense do
119
    begin
120
      CBValidity.Checked := FieldByName('Validity').AsBoolean;
121
      RBOrder.Checked := FieldByName('Type').AsInteger = 0;
122
      POrderNumber.Visible := RBOrder.Checked;
123
      EOrderNumber.Text := FieldByName('Source').AsString;
124
      RBINRA.Checked := FieldByName('Type').AsInteger = 1;
125
      RBAjinomoto.Checked := FieldByName('Type').AsInteger = 2;
126
      PAjinomotoNumber.Visible := RBAjinomoto.Checked;
127
      EAjinomotoNumber.Text := FieldByName('Source').AsString;
128
      EFirstName.Text := FieldByName('FirstName').AsString;
129
      ELastName.Text := FieldByName('LastName').AsString;
130
      ECompany.Text := FieldByName('Company').AsString;
131
      EMail.Text := FieldByName('Mail').AsString;
132
      DTPFinalDate.DateTime := FieldByName('FinalDate').AsDateTime;
133
      ESoftwareEnableKey.Text := FieldByName('SoftwareEnableKey').AsString;
134
      EInfoChange(nil);
135
    end;
136
  end
137
  else
138
  begin
139
    PInfo.Visible := FALSE;
140
    CBValidity.Visible := FALSE;
141
    LLicenseNotFound.Visible := TRUE;
142
  end;
143
end;
144

    
145
procedure TFManual.EInfoChange(Sender: TObject);
146
begin
147
  if not FMenu.TLicense.FieldByName('Version').IsNull
148
    and (Length(EFirstName.Text) > 0)
149
    and (Length(ELastName.Text) > 0)
150
    and not FMenu.TLicense.FieldByName('VolumeSerialNumber').IsNull
151
    and AnsiSameText(ESoftwareEnableKey.Text, FMenu.CompleteKey(PBLicenseNumber.Value, FMenu.TLicense.FieldByName('Version').AsString, EFirstName.Text, ELastName.Text, ECompany.Text, FMenu.TLicense.FieldByName('VolumeSerialNumber').AsString, DateToStr(DTPFinalDate.Date)))
152
  then
153
  begin
154
    BBSend.Enabled := TRUE;
155
    BBSave.Enabled := TRUE;
156
  end
157
  else
158
  begin
159
    BBSend.Enabled := FALSE;
160
    BBSave.Enabled := FALSE;
161
  end;
162
  if not FMenu.TLicense.FieldByName('Version').IsNull
163
    and (Length(EFirstName.Text) > 0)
164
    and (Length(ELastName.Text) > 0)
165
    and not FMenu.TLicense.FieldByName('VolumeSerialNumber').IsNull
166
    and not AnsiSameText(ESoftwareEnableKey.Text, FMenu.CompleteKey(PBLicenseNumber.Value, FMenu.TLicense.FieldByName('Version').AsString, EFirstName.Text, ELastName.Text, ECompany.Text, FMenu.TLicense.FieldByName('VolumeSerialNumber').AsString, DateToStr(DTPFinalDate.Date)))
167
  then
168
    BBKeyCompute.Enabled := TRUE
169
  else
170
    BBKeyCompute.Enabled := FALSE;
171
end;
172

    
173
procedure TFManual.BBKeyComputeClick(Sender: TObject);
174
begin
175
  ESoftwareEnableKey.Text := FMenu.CompleteKey(PBLicenseNumber.Value, FMenu.TLicense.FieldByName('Version').AsString, EFirstName.Text, ELastName.Text, ECompany.Text, FMenu.TLicense.FieldByName('VolumeSerialNumber').AsString, DateToStr(DTPFinalDate.Date));
176
  EInfoChange(nil);
177
end;
178

    
179
procedure TFManual.BBSendClick(Sender: TObject);
180
var
181
  f: TIniFile;
182
  choix: integer;
183
  StrMessage: TStrings;
184
begin
185
  FMenu.MLog.Lines.Add('Updating license...');
186
  with FMenu.TLicense do
187
  begin
188
    Edit;
189
    FieldByName('FirstName').AsString := EFirstName.Text;
190
    FieldByName('LastName').AsString := ELastName.Text;
191
    FieldByName('Company').AsString := ECompany.Text;
192
    FieldByName('Mail').AsString := EMail.Text;
193
    FieldByName('FinalDate').AsDateTime := DTPFinalDate.DateTime;
194
    FieldByName('SoftwareEnableKey').AsString := ESoftwareEnableKey.Text;
195
    Post;
196
    try
197
      f := TIniFile.Create(TempFolder + '\InraPorc.lic');
198
      f.WriteInteger ('License', 'LicenseType', 2);
199
      f.WriteInteger ('License', 'LicenseNumber', FieldByName('LicenseNumber').AsInteger) ;
200
      f.WriteString ('License', 'Version', FieldByName('Version').AsString);
201
      f.WriteString ('License', 'FirstName', FieldByName('FirstName').AsString);
202
      f.WriteString ('License', 'LastName', FieldByName('LastName').AsString);
203
      f.WriteString ('License', 'Company', FieldByName('Company').AsString);
204
      f.WriteString ('License', 'Address1', FieldByName('Address1').AsString);
205
      f.WriteString ('License', 'Address2', FieldByName('Address2').AsString);
206
      f.WriteString ('License', 'PostalCode', FieldByName('PostalCode').AsString);
207
      f.WriteString ('License', 'City', FieldByName('City').AsString);
208
      f.WriteString ('License', 'Country', FieldByName('Country').AsString);
209
      f.WriteString ('License', 'Phone', FieldByName('Phone').AsString);
210
      f.WriteString ('License', 'Fax', FieldByName('Fax').AsString);
211
      f.WriteString ('License', 'Mail', FieldByName('Mail').AsString);
212
      f.WriteString ('License', 'VolumeSerialNumber', FieldByName('VolumeSerialNumber').AsString);
213
      f.WriteString ('License', 'FinalDate', DateToStr(FieldByName('FinalDate').AsDateTime));
214
      f.WriteString ('License', 'SoftwareEnableKey', FieldByName('SoftwareEnableKey').AsString);
215
      f.Free;
216
      choix := MessageDlg('Envoyer le fichier de licence' + sLineBreak + '- en tant que pi?ce jointe (Oui)' + sLineBreak + '- int?gr? dans le message (Non)', mtConfirmation, [mbYes, mbNo], 0);
217
      FMenu.MLog.Lines.Add('Mailing to ' + EMail.Text + '...');
218
      with MKey do
219
      begin
220
        Body.Clear;
221
        MessageParts.Clear;
222
        From.Name := 'InraPorc';
223
        From.Address := MAIL_INRAPORC;
224
        Recipients.EMailAddresses := EMail.Text;
225
        StrMessage := TStringList.Create;
226
        if FieldByName('Language').AsString = 'FR'
227
        then // R?ponse (fran?ais)
228
        begin
229
          Subject := Format('[InraPorc] Cl? d''activation pour licence num?ro %d', [PBLicenseNumber.Value]);
230
          if choix = mrYes
231
          then
232
            StrMessage.LoadFromFile(SHARED_DRIVE + SHARED_FOLDER + 'Messages\ManuelAttach?_FR.txt')
233
          else
234
            StrMessage.LoadFromFile(SHARED_DRIVE + SHARED_FOLDER + 'Messages\ManuelInt?gr?_FR.txt');
235
          Body.AddStrings(StrMessage);
236
          Body.Add(Format('La cl? d''activation est valable jusqu''au %s.', [DateToStr(DTPFinalDate.Date)]));
237
          Body.Add('Un nouveau fichier de licence vous sera automatiquement envoy? avant la prochaine date d''expiration.');
238
          Body.Add('');
239
          StrMessage.LoadFromFile(SHARED_DRIVE + SHARED_FOLDER + 'Messages\Signature_FR.txt');
240
          Body.AddStrings(StrMessage);
241
        end
242
        else // Reply (english)
243
        begin
244
          Subject := Format('[InraPorc] License activation key for license number %d', [PBLicenseNumber.Value]);
245
          if choix = mrYes
246
          then
247
            StrMessage.LoadFromFile(SHARED_DRIVE + SHARED_FOLDER + 'Messages\ManuelAttach?_EN.txt')
248
          else
249
            StrMessage.LoadFromFile(SHARED_DRIVE + SHARED_FOLDER + 'Messages\ManuelInt?gr?_EN.txt');
250
          Body.AddStrings(StrMessage);
251
          Body.Append(Format('The license activation key is valid until %s.', [DateToStr(DTPFinalDate.Date)]));
252
          Body.Append('You will automatically receive a new license file before the next expiration date.');
253
          Body.Add('');
254
          StrMessage.LoadFromFile(SHARED_DRIVE + SHARED_FOLDER + 'Messages\Signature_EN.txt');
255
          Body.AddStrings(StrMessage);
256
        end;
257
        StrMessage.Free;
258
      end;
259
      if FileExists(TempFolder + '\InraPorc.lic')
260
      then
261
      begin
262
        if choix = mrYes
263
        then
264
          TIdAttachmentFile.Create(MKey.MessageParts, TempFolder + '\InraPorc.lic')
265
        else
266
        begin
267
          MFile.Lines.LoadFromFile(TempFolder + '\InraPorc.lic');
268
          MKey.Body.Add('');
269
          MKey.Body.Add('********** InraPorc.lic **********');
270
          if FieldByName('Language').AsString = 'FR'
271
          then // R?ponse (fran?ais)
272
            MKey.Body.Add('; Copier ? partir de cette ligne')
273
          else // Reply (english)
274
            MKey.Body.Add('; Copy from this line');
275
          MKey.Body.Add('');
276
          MKey.Body.AddStrings(MFile.Lines);
277
          MKey.Body.Add('');
278
          if FieldByName('Language').AsString = 'FR'
279
          then // R?ponse (fran?ais)
280
            MKey.Body.Add('; Copier jusqu''? cette ligne')
281
          else // Reply (english)
282
            MKey.Body.Add('; Copy until this line');
283
          MKey.Body.Add('**********  InraPorc.lic  **********');
284
        end;
285
        FMenu.MLog.Lines.Add('SMTP...');
286
        try
287
          SMTP.Connect;
288
          try
289
            SMTP.Send(MKey);
290
          finally
291
            SMTP.Disconnect;
292
            if IMAP4.Connect
293
            then
294
              try
295
                if not IMAP4.AppendMsg('?l?ments envoy?s', MKey, MKey.LastGeneratedHeaders)
296
                then
297
                  FMenu.MLog.Lines.Add('Message could not be copied in IMAP server !');
298
              finally
299
                IMAP4.Disconnect;
300
              end
301
            else
302
              FMenu.MLog.Lines.Add('IMAP server could not be connected !');
303
          end;
304
        except
305
          FMenu.MLog.Lines.Add('Message could not be sent !');
306
        end;
307
        if not DeleteFile(TempFolder + '\InraPorc.lic')
308
        then
309
          FMenu.MLog.Lines.Add('File InraPorc.lic could not be deleted !');
310
      end
311
      else
312
        FMenu.MLog.Lines.Add('File InraPorc.lic could not be found !');
313
    except
314
      FMenu.MLog.Lines.Add('File InraPorc.lic could not be created !');
315
    end;
316
  end;
317
  FMenu.MLog.Lines.Add('Logging record...');
318
  with FMenu.TLicenses do
319
  begin
320
    Append;
321
    FieldByName('Date').AsDateTime := Now;
322
    FieldByName('Admin').AsString := FMenu.EAdmin.Text;
323
    FieldByName('Key').AsString := '<Manuel>';
324
    FieldByName('Language').AsString := FMenu.TLicense.FieldByName('Language').AsString;
325
    FieldByName('LicenseType').AsInteger := 2;
326
    FieldByName('LicenseNumber').AsInteger := FMenu.TLicense.FieldByName('LicenseNumber').AsInteger;
327
    FieldByName('Version').AsString := FMenu.TLicense.FieldByName('Version').AsString;
328
    FieldByName('FirstName').AsString := FMenu.TLicense.FieldByName('FirstName').AsString;
329
    FieldByName('LastName').AsString := FMenu.TLicense.FieldByName('LastName').AsString;
330
    FieldByName('Company').AsString := FMenu.TLicense.FieldByName('Company').AsString;
331
    FieldByName('Address1').AsString := FMenu.TLicense.FieldByName('Address1').AsString;
332
    FieldByName('Address2').AsString := FMenu.TLicense.FieldByName('Address2').AsString;
333
    FieldByName('PostalCode').AsString := FMenu.TLicense.FieldByName('PostalCode').AsString;
334
    FieldByName('City').AsString := FMenu.TLicense.FieldByName('City').AsString;
335
    FieldByName('Country').AsString := FMenu.TLicense.FieldByName('Country').AsString;
336
    FieldByName('Phone').AsString := FMenu.TLicense.FieldByName('Phone').AsString;
337
    FieldByName('Fax').AsString := FMenu.TLicense.FieldByName('Fax').AsString;
338
    FieldByName('Mail').AsString := FMenu.TLicense.FieldByName('Mail').AsString;
339
    FieldByName('VolumeSerialNumber').AsString := FMenu.TLicense.FieldByName('VolumeSerialNumber').AsString;
340
    FieldByName('FinalDate').AsString := DateToStr(FMenu.TLicense.FieldByName('FinalDate').AsDateTime);
341
    FieldByName('SoftwareEnableKey').AsString := FMenu.TLicense.FieldByName('SoftwareEnableKey').AsString;
342
    Post;
343
  end;
344
  Close;
345
end;
346

    
347
procedure TFManual.BBSaveClick(Sender: TObject);
348
var
349
  f: TIniFile;
350
begin
351
  FMenu.MLog.Lines.Add('Updating license...');
352
  with FMenu.TLicense do
353
  begin
354
    Edit;
355
    FieldByName('FirstName').AsString := EFirstName.Text;
356
    FieldByName('LastName').AsString := ELastName.Text;
357
    FieldByName('Company').AsString := ECompany.Text;
358
    FieldByName('Mail').AsString := EMail.Text;
359
    FieldByName('FinalDate').AsDateTime := DTPFinalDate.DateTime;
360
    FieldByName('SoftwareEnableKey').AsString := ESoftwareEnableKey.Text;
361
    Post;
362
    FMenu.MLog.Lines.Add('Saving to InraPorc.lic');
363
    try
364
      f := TIniFile.Create(SHARED_DRIVE + SHARED_FOLDER + 'Fichiers\InraPorc.lic');
365
      f.WriteInteger ('License', 'LicenseType', 2);
366
      f.WriteInteger ('License', 'LicenseNumber', FieldByName('LicenseNumber').AsInteger) ;
367
      f.WriteString ('License', 'Version', FieldByName('Version').AsString);
368
      f.WriteString ('License', 'FirstName', FieldByName('FirstName').AsString);
369
      f.WriteString ('License', 'LastName', FieldByName('LastName').AsString);
370
      f.WriteString ('License', 'Company', FieldByName('Company').AsString);
371
      f.WriteString ('License', 'Address1', FieldByName('Address1').AsString);
372
      f.WriteString ('License', 'Address2', FieldByName('Address2').AsString);
373
      f.WriteString ('License', 'PostalCode', FieldByName('PostalCode').AsString);
374
      f.WriteString ('License', 'City', FieldByName('City').AsString);
375
      f.WriteString ('License', 'Country', FieldByName('Country').AsString);
376
      f.WriteString ('License', 'Phone', FieldByName('Phone').AsString);
377
      f.WriteString ('License', 'Fax', FieldByName('Fax').AsString);
378
      f.WriteString ('License', 'Mail', FieldByName('Mail').AsString);
379
      f.WriteString ('License', 'VolumeSerialNumber', FieldByName('VolumeSerialNumber').AsString);
380
      f.WriteString ('License', 'FinalDate', DateToStr(FieldByName('FinalDate').AsDateTime));
381
      f.WriteString ('License', 'SoftwareEnableKey', FieldByName('SoftwareEnableKey').AsString);
382
      f.Free;
383
    except
384
      FMenu.MLog.Lines.Add('File InraPorc.lic could not be created !');
385
    end;
386
  end;
387
  FMenu.MLog.Lines.Add('Logging record...');
388
  with FMenu.TLicenses do
389
  begin
390
    Append;
391
    FieldByName('Date').AsDateTime := Now;
392
    FieldByName('Admin').AsString := FMenu.EAdmin.Text;
393
    FieldByName('Key').AsString := '<Manuel>';
394
    FieldByName('Language').AsString := FMenu.TLicense.FieldByName('Language').AsString;
395
    FieldByName('LicenseType').AsInteger := 2;
396
    FieldByName('LicenseNumber').AsInteger := FMenu.TLicense.FieldByName('LicenseNumber').AsInteger;
397
    FieldByName('Version').AsString := FMenu.TLicense.FieldByName('Version').AsString;
398
    FieldByName('FirstName').AsString := FMenu.TLicense.FieldByName('FirstName').AsString;
399
    FieldByName('LastName').AsString := FMenu.TLicense.FieldByName('LastName').AsString;
400
    FieldByName('Company').AsString := FMenu.TLicense.FieldByName('Company').AsString;
401
    FieldByName('Address1').AsString := FMenu.TLicense.FieldByName('Address1').AsString;
402
    FieldByName('Address2').AsString := FMenu.TLicense.FieldByName('Address2').AsString;
403
    FieldByName('PostalCode').AsString := FMenu.TLicense.FieldByName('PostalCode').AsString;
404
    FieldByName('City').AsString := FMenu.TLicense.FieldByName('City').AsString;
405
    FieldByName('Country').AsString := FMenu.TLicense.FieldByName('Country').AsString;
406
    FieldByName('Phone').AsString := FMenu.TLicense.FieldByName('Phone').AsString;
407
    FieldByName('Fax').AsString := FMenu.TLicense.FieldByName('Fax').AsString;
408
    FieldByName('Mail').AsString := FMenu.TLicense.FieldByName('Mail').AsString;
409
    FieldByName('VolumeSerialNumber').AsString := FMenu.TLicense.FieldByName('VolumeSerialNumber').AsString;
410
    FieldByName('FinalDate').AsString := DateToStr(FMenu.TLicense.FieldByName('FinalDate').AsDateTime);
411
    FieldByName('SoftwareEnableKey').AsString := FMenu.TLicense.FieldByName('SoftwareEnableKey').AsString;
412
    Post;
413
  end;
414
  Close;
415
end;
416

    
417
end.