Statistiques
| Révision:

root / LicensesMercure / UFAjinomoto.pas @ 1

Historique | Voir | Annoter | Télécharger (10,552 ko)

1
unit UFAjinomoto;
2

    
3
interface
4

    
5
uses
6
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7
    Dialogs, StdCtrls, Buttons, PBNumEdit, IdBaseComponent, IdComponent,
8
    IdTCPConnection, IdTCPClient, IdFTP, ShellAPI, IdMessage, IdMessageClient,
9
    IdSMTP, ExtCtrls, mysql, IdExplicitTLSClientServerBase, IdSMTPBase, IdIMAP4,
10
  IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL;
11

    
12
type
13
  TFAjinomoto = class(TForm)
14
    EKey: TEdit;
15
    BBSkip: TBitBtn;
16
    BBProcess: TBitBtn;
17
    BBRemove: TBitBtn;
18
    EUser: TEdit;
19
    LUser: TLabel;
20
    LLicenses: TLabel;
21
    EFirstName1: TEdit;
22
    LFirstName: TLabel;
23
    ELastName1: TEdit;
24
    LLastName: TLabel;
25
    LLicenseNumber: TLabel;
26
    EFirstName2: TEdit;
27
    ELastName2: TEdit;
28
    EFirstName3: TEdit;
29
    ELastName3: TEdit;
30
    EFirstName4: TEdit;
31
    ELastName4: TEdit;
32
    EFirstName5: TEdit;
33
    ELastName5: TEdit;
34
    PBLicenses: TPBNumEdit;
35
    PBLicenseNumber1: TPBNumEdit;
36
    PBLicenseNumber2: TPBNumEdit;
37
    PBLicenseNumber3: TPBNumEdit;
38
    PBLicenseNumber4: TPBNumEdit;
39
    PBLicenseNumber5: TPBNumEdit;
40
    SMTP: TIdSMTP;
41
    MObservations: TMemo;
42
    MAjinomoto: TIdMessage;
43
    EFormationDate: TEdit;
44
    EFormationPlace: TEdit;
45
    LFormationDate: TLabel;
46
    LFormationPlace: TLabel;
47
    EFirstName6: TEdit;
48
    ELastName6: TEdit;
49
    EFirstName7: TEdit;
50
    ELastName7: TEdit;
51
    EFirstName8: TEdit;
52
    ELastName8: TEdit;
53
    EFirstName9: TEdit;
54
    ELastName9: TEdit;
55
    EFirstName10: TEdit;
56
    ELastName10: TEdit;
57
    PBLicenseNumber6: TPBNumEdit;
58
    PBLicenseNumber7: TPBNumEdit;
59
    PBLicenseNumber8: TPBNumEdit;
60
    PBLicenseNumber9: TPBNumEdit;
61
    PBLicenseNumber10: TPBNumEdit;
62
    EFirstName11: TEdit;
63
    ELastName11: TEdit;
64
    EFirstName12: TEdit;
65
    ELastName12: TEdit;
66
    EFirstName13: TEdit;
67
    ELastName13: TEdit;
68
    EFirstName14: TEdit;
69
    ELastName14: TEdit;
70
    EFirstName15: TEdit;
71
    ELastName15: TEdit;
72
    PBLicenseNumber11: TPBNumEdit;
73
    PBLicenseNumber12: TPBNumEdit;
74
    PBLicenseNumber13: TPBNumEdit;
75
    PBLicenseNumber14: TPBNumEdit;
76
    PBLicenseNumber15: TPBNumEdit;
77
    EFirstName16: TEdit;
78
    ELastName16: TEdit;
79
    EFirstName17: TEdit;
80
    ELastName17: TEdit;
81
    EFirstName18: TEdit;
82
    ELastName18: TEdit;
83
    EFirstName19: TEdit;
84
    ELastName19: TEdit;
85
    EFirstName20: TEdit;
86
    ELastName20: TEdit;
87
    PBLicenseNumber16: TPBNumEdit;
88
    PBLicenseNumber17: TPBNumEdit;
89
    PBLicenseNumber18: TPBNumEdit;
90
    PBLicenseNumber19: TPBNumEdit;
91
    PBLicenseNumber20: TPBNumEdit;
92
    PLicenses: TPanel;
93
    LCompany: TLabel;
94
    ECompany1: TEdit;
95
    ECompany2: TEdit;
96
    ECompany3: TEdit;
97
    ECompany4: TEdit;
98
    ECompany5: TEdit;
99
    ECompany6: TEdit;
100
    ECompany7: TEdit;
101
    ECompany8: TEdit;
102
    ECompany9: TEdit;
103
    ECompany10: TEdit;
104
    ECompany11: TEdit;
105
    ECompany12: TEdit;
106
    ECompany13: TEdit;
107
    ECompany14: TEdit;
108
    ECompany15: TEdit;
109
    ECompany16: TEdit;
110
    ECompany17: TEdit;
111
    ECompany18: TEdit;
112
    ECompany19: TEdit;
113
    ECompany20: TEdit;
114
    LFormation: TLabel;
115
    PLicense1: TPanel;
116
    PLicense2: TPanel;
117
    PLicense3: TPanel;
118
    PLicense4: TPanel;
119
    PLicense5: TPanel;
120
    PLicense6: TPanel;
121
    PLicense7: TPanel;
122
    PLicense8: TPanel;
123
    PLicense9: TPanel;
124
    PLicense10: TPanel;
125
    PLicense11: TPanel;
126
    PLicense12: TPanel;
127
    PLicense13: TPanel;
128
    PLicense14: TPanel;
129
    PLicense15: TPanel;
130
    PLicense16: TPanel;
131
    PLicense17: TPanel;
132
    PLicense18: TPanel;
133
    PLicense19: TPanel;
134
    PLicense20: TPanel;
135
    IMAP4: TIdIMAP4;
136
    OpenSSL_IMAP4: TIdSSLIOHandlerSocketOpenSSL;
137
    OpenSSL_SMTP: TIdSSLIOHandlerSocketOpenSSL;
138
    procedure FormShow(Sender: TObject);
139
    procedure BBSkipClick(Sender: TObject);
140
    procedure BBProcessClick(Sender: TObject);
141
    procedure BBRemoveClick(Sender: TObject);
142
    procedure FormCreate(Sender: TObject);
143
  private
144
    { D?clarations priv?es }
145
    Key: String;
146
    Language: String;
147
    User: String;
148
    FormationDate, FormationPlace: String;
149
    Licenses: Integer;
150
    FirstName, LastName, Company: array[1..20] of String;
151
    Observations: AnsiString;
152
    procedure DisplayRequest;
153
  public
154
    { D?clarations publiques }
155
    function GetRequest: Boolean;
156
  end;
157

    
158
var
159
  FAjinomoto: TFAjinomoto;
160

    
161
implementation
162

    
163
uses
164
  UFMenu;
165

    
166
{$R *.dfm}
167

    
168
procedure TFAjinomoto.FormCreate(Sender: TObject);
169
begin
170
  Top := 0;
171
  Left := 0;
172
  with IMAP4 do
173
  begin
174
    Host := IMAP_SERVER;
175
//    Username := EXCHANGE_USERNAME + '\' + EXCHANGE_SHARED_MAILBOX;
176
    Username := 'INRA\' + FMenu.EUsername.Text + '\' + EXCHANGE_SHARED_MAILBOX;
177
//    Password := EXCHANGE_PASSWORD;
178
    Password := FMenu.EPassword.Text;
179
  end;
180
  with SMTP do
181
  begin
182
    Host := SMTP_SERVER;
183
//    Username := EXCHANGE_USERNAME;
184
    Username := 'INRA\' + FMenu.EUsername.Text;
185
//    Password := EXCHANGE_PASSWORD;
186
    Password := FMenu.EPassword.Text;
187
  end;
188
end;
189

    
190
procedure TFAjinomoto.FormShow(Sender: TObject);
191
begin
192
  DisplayRequest;
193
end;
194

    
195
procedure TFAjinomoto.BBSkipClick(Sender: TObject);
196
begin
197
  Inc(cur);
198
  if (cur < SLAjinomoto.Count) and GetRequest
199
  then
200
    DisplayRequest
201
  else
202
    Close;
203
end;
204

    
205
procedure TFAjinomoto.BBProcessClick(Sender: TObject);
206
var
207
  i: Integer;
208
  p: TPanel;
209
begin
210
  FMenu.MLog.Lines.Add('Recording licenses (type 2)...');
211
  for i := 1 to Licenses do
212
    with FMenu.TLicense do
213
    begin
214
      Insert;
215
      FieldByName('Validity').AsBoolean := False;
216
      FieldByName('Type').AsInteger := 2;
217
      FieldByName('Source').AsString := Key;
218
      p := PLicenses.Controls[i + 3] as TPanel;
219
      FieldByName('LicenseNumber').AsInteger := (p.Controls[3] as TPBNumEdit).AsInteger;
220
      FieldByName('FirstName').AsString := (p.Controls[0] as TEdit).Text;
221
      FieldByName('LastName').AsString := (p.Controls[1] as TEdit).Text;
222
      FieldByName('Company').AsString := (p.Controls[2] as TEdit).Text;
223
      FieldByName('FinalDate').AsDateTime := IncMonth(Date, 2);
224
      Post;
225
    end;
226
  FMenu.MLog.Lines.Add('Mailing to ' + MAIL_AJINOMOTO + '...');
227
  with MAjinomoto do
228
  begin
229
    Body.Clear;
230
    From.Name := 'InraPorc';
231
    From.Address := MAIL_INRAPORC;
232
    Recipients.EMailAddresses := MAIL_AJINOMOTO;
233
    Body.Add(Format('Attribution de licence Ajinomoto num?ro "%s" portant sur %d licence(s)', [Key, PBLicenses.AsInteger]));
234
    Body.Add('');
235
    Body.Add('Les num?ros de licence suivants ont ?t? attribu?s :');
236
    for i := 1 to PBLicenses.AsInteger do
237
    begin
238
      p := PLicenses.Controls[i + 3] as TPanel;
239
      Body.Add(Format('%d - %s %s (%s)', [(p.Controls[3] as TPBNumEdit).AsInteger, (p.Controls[0] as TEdit).Text, (p.Controls[1] as TEdit).Text, (p.Controls[2] as TEdit).Text]));
240
    end;
241
    Body.Add('');
242
    Body.Add('Merci de communiquer les num?ros de licence aux personnes concern?es.');
243
    Body.Add('');
244
    Body.Add('Cordialement');
245
    Body.Add('--');
246
    Body.Add(FMenu.EAdmin.Text);
247
  end;
248
  FMenu.MLog.Lines.Add('SMTP...');
249
  try
250
    SMTP.Connect;
251
    try
252
      SMTP.Send(MAjinomoto);
253
    finally
254
      SMTP.Disconnect;
255
      if IMAP4.Connect
256
      then
257
        try
258
          if not IMAP4.AppendMsg('?l?ments envoy?s', MAjinomoto, MAjinomoto.LastGeneratedHeaders)
259
          then
260
            FMenu.MLog.Lines.Add('Message could not be copied in IMAP server !');
261
        finally
262
          IMAP4.Disconnect;
263
        end
264
      else
265
        FMenu.MLog.Lines.Add('IMAP server could not be connected !');
266
    end;
267
  except
268
    FMenu.MLog.Lines.Add('Message could not be sent !');
269
  end;
270
  BBRemoveClick(nil);
271
end;
272

    
273
procedure TFAjinomoto.BBRemoveClick(Sender: TObject);
274
var
275
  i: Integer;
276
begin
277
  FMenu.MLog.Lines.Add('Logging record...');
278
  with FMenu.TAjinomoto do
279
  begin
280
    Append;
281
    FieldByName('Date').AsDateTime := Now;
282
    FieldByName('Admin').AsString := FMenu.EAdmin.Text;
283
    FieldByName('Key').AsString := Key;
284
    FieldByName('Language').AsString := Language;
285
    FieldByName('User').AsString := User;
286
    FieldByName('FormationDate').AsString := FormationDate;
287
    FieldByName('FormationPlace').AsString := FormationPlace;
288
    FieldByName('Licenses').AsInteger := Licenses;
289
    for i := 1 to 20 do
290
    begin
291
      FieldByName(Format('FirstName%d', [i])).AsString := FirstName[i];
292
      FieldByName(Format('LastName%d', [i])).AsString := LastName[i];
293
      FieldByName(Format('Company%d', [i])).AsString := Company[i];
294
    end;
295
    FieldByName('Observations').AsVariant := Observations;
296
    Post;
297
  end;
298
  que := 'DELETE FROM `ajinomoto` where `Key` = ''' + SLAjinomoto[cur] + '''';
299
  FMenu.MLog.Lines.Add(que);
300
  if mysql_query(con, PAnsiChar(que)) <> 0
301
  then
302
    FMenu.MLog.Lines.Add(mysql_error(con))
303
  else
304
  begin
305
    SLAjinomoto.Delete(cur);
306
    FMenu.PBAjinomoto.AsInteger := FMenu.PBAjinomoto.AsInteger - 1;
307
    Dec(cur);
308
  end;
309
  BBSkipClick(nil);
310
end;
311

    
312
function TFAjinomoto.GetRequest: Boolean;
313
var
314
  i: Integer;
315
begin
316
  Result := False;
317
  que := 'SELECT * FROM `ajinomoto` where `Key` = ''' + SLAjinomoto[cur] + '''';
318
  FMenu.MLog.Lines.Add(que);
319
  if mysql_query(con, PAnsiChar(que)) <> 0
320
  then
321
    FMenu.MLog.Lines.Add(mysql_error(con))
322
  else
323
  begin
324
    res := mysql_store_result(con);
325
    if res = nil
326
    then
327
      FMenu.MLog.Lines.Add(mysql_error(con))
328
    else
329
    begin
330
      row := mysql_fetch_row(res);
331
      if row = nil
332
      then
333
        FMenu.MLog.Lines.Add(mysql_error(con))
334
      else
335
      begin
336
        Key := row^[0];
337
        Language := row^[1];
338
        User := row^[2];
339
        FormationDate := row^[3];
340
        FormationPlace := row^[4];
341
        Licenses := StrToInt(row^[5]);
342
        for i := 1 to 20 do
343
        begin
344
          FirstName[i] := row^[3*i+3];
345
          LastName[i] := row^[3*i+4];
346
          Company[i] := row^[3*i+5];
347
        end;
348
        Observations := row^[66];
349
        Result := True;
350
      end;
351
      mysql_free_result(res);
352
    end;
353
  end;
354
end;
355

    
356
procedure TFAjinomoto.DisplayRequest;
357
var
358
  i: Integer;
359
  p: TPanel;
360
begin
361
  EKey.Text := Key;
362
  EUser.Text := User;
363
  EFormationDate.Text := FormationDate;
364
  EFormationPlace.Text := FormationPlace;
365
  PBLicenses.AsInteger := Licenses;
366
  for i := 1 to 20 do
367
  begin
368
    p := PLicenses.Controls[i + 3] as TPanel;
369
    p.Visible := i <= Licenses;
370
    (p.Controls[0] as TEdit).Text := FirstName[i];
371
    (p.Controls[1] as TEdit).Text := LastName[i];
372
    (p.Controls[2] as TEdit).Text := Company[i];
373
    (p.Controls[3] as TPBNumEdit).AsInteger := FMenu.TLicense.RecordCount + i;
374
  end;
375
  MObservations.Text := Observations;
376
end;
377

    
378
end.