Statistiques
| Révision:

root / UnitIngredientDetail.pas @ 4

Historique | Voir | Annoter | Télécharger (37,368 ko)

1 1 avalancogn
unit UnitIngredientDetail;
2
3
{$WARN SYMBOL_PLATFORM OFF}
4
5
interface
6
7
uses
8
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
9
  Dialogs, gnugettext, StdCtrls, ComCtrls, ExtCtrls, Mask, DB, DBCtrls,
10
  ActnList, ImgList, ToolWin, JvExStdCtrls, JvEdit, JvValidateEdit, RpBase,
11
  RpSystem, RpRender, RpRenderPDF, RpRave, RpDefine, RpCon, RpConDS, JvCsvData,
12
  RvClass, RvCsStd, RvCsData, JvButton, JvCtrls, XMLIntf, XMLDoc, RpDevice;
13
14
type
15
  TFormIngredientDetail = class(TForm)
16
    RvDataSetConnectionIngredients: TRvDataSetConnection;
17
    RvProjectReport: TRvProject;
18
    RvSystemReport: TRvSystem;
19
    SaveDialogExport: TSaveDialog;
20
    ActionListButtons: TActionList;
21
    ActionHelp: TAction;
22
    ActionClose: TAction;
23
    ImageListIcons: TImageList;
24
    ActionModify: TAction;
25
    ActionDelete: TAction;
26
    ActionPrint: TAction;
27
    ActionXML: TAction;
28
    PanelButtons: TPanel;
29
    PanelMain: TPanel;
30
    LabelClass: TLabel;
31
    LabelDefinition: TLabel;
32
    LabelMS: TLabel;
33
    LabelName: TLabel;
34
    LabelSource: TLabel;
35
    DBEditClass: TDBEdit;
36
    DBEditMS: TDBEdit;
37
    DBEditName: TDBEdit;
38
    DBEditSource: TDBEdit;
39
    DBMemoDefinition: TDBMemo;
40
    GroupBoxAA: TGroupBox;
41
    LabelAADig: TLabel;
42
    LabelAATot: TLabel;
43
    LabelLys: TLabel;
44
    LabelTyr: TLabel;
45
    LabelThr: TLabel;
46
    LabelPheTyr: TLabel;
47
    LabelMet: TLabel;
48
    LabelHis: TLabel;
49
    LabelCys: TLabel;
50
    LabelArg: TLabel;
51
    LabelMetCys: TLabel;
52
    LabelAla: TLabel;
53
    LabelTrp: TLabel;
54
    LabelAsp: TLabel;
55
    LabelIle: TLabel;
56
    LabelGlu: TLabel;
57
    LabelVal: TLabel;
58
    LabelGly: TLabel;
59
    LabelLeu: TLabel;
60
    LabelSer: TLabel;
61
    LabelPhe: TLabel;
62
    LabelPro: TLabel;
63
    LabeldAA: TLabel;
64
    DBEditLys: TDBEdit;
65
    DBEditLysd: TDBEdit;
66
    DBEditTyr: TDBEdit;
67
    DBEditTyrd: TDBEdit;
68
    DBEditThr: TDBEdit;
69
    DBEditThrd: TDBEdit;
70
    DBEditPheTyr: TDBEdit;
71
    DBEditPheTyrd: TDBEdit;
72
    DBEditMet: TDBEdit;
73
    DBEditMetd: TDBEdit;
74
    DBEditHis: TDBEdit;
75
    DBEditHisd: TDBEdit;
76
    DBEditCys: TDBEdit;
77
    DBEditCysd: TDBEdit;
78
    DBEditArg: TDBEdit;
79
    DBEditArgd: TDBEdit;
80
    DBEditMetCys: TDBEdit;
81
    DBEditMetCysd: TDBEdit;
82
    DBEditAla: TDBEdit;
83
    DBEditAlad: TDBEdit;
84
    DBEditTrp: TDBEdit;
85
    DBEditTrpd: TDBEdit;
86
    DBEditAsp: TDBEdit;
87
    DBEditAspd: TDBEdit;
88
    DBEditIle: TDBEdit;
89
    DBEditIled: TDBEdit;
90
    DBEditGlu: TDBEdit;
91
    DBEditGlud: TDBEdit;
92
    DBEditVal: TDBEdit;
93
    DBEditVald: TDBEdit;
94
    DBEditGly: TDBEdit;
95
    DBEditGlyd: TDBEdit;
96
    DBEditLeu: TDBEdit;
97
    DBEditLeud: TDBEdit;
98
    DBEditSer: TDBEdit;
99
    DBEditSerd: TDBEdit;
100
    DBEditPhe: TDBEdit;
101
    DBEditPhed: TDBEdit;
102
    DBEditPro: TDBEdit;
103
    DBEditProd: TDBEdit;
104
    DEditdLys: TDBEdit;
105
    DBEditdTyr: TDBEdit;
106
    DBEditdThr: TDBEdit;
107
    DBEditdPheTyr: TDBEdit;
108
    DBEditdMet: TDBEdit;
109
    DBEditdHis: TDBEdit;
110
    DBEditdCys: TDBEdit;
111
    DBEditdArg: TDBEdit;
112
    DBEditdMetCys: TDBEdit;
113
    DBEditdAla: TDBEdit;
114
    DBEditdTrp: TDBEdit;
115
    DBEditdAsp: TDBEdit;
116
    DBEditdIle: TDBEdit;
117
    DBEditdGlu: TDBEdit;
118
    DBEditdVal: TDBEdit;
119
    DBEditdGly: TDBEdit;
120
    DBEditdLeu: TDBEdit;
121
    DBEditdSer: TDBEdit;
122
    DBEditdPhe: TDBEdit;
123
    DBEditdPro: TDBEdit;
124
    GroupBoxAzote: TGroupBox;
125
    LabelCrois3: TLabel;
126
    LabelTruie3: TLabel;
127
    LabeldN: TLabel;
128
    DBEditdNc: TDBEdit;
129
    DBEditdNt: TDBEdit;
130
    GroupBoxEnergy: TGroupBox;
131
    LabelEB: TLabel;
132
    LabelED: TLabel;
133
    LabelEM: TLabel;
134
    LabelEN: TLabel;
135
    LabelCrois1: TLabel;
136
    LabelTruie1: TLabel;
137
    LabelRatio: TLabel;
138
    DBEditEBc: TDBEdit;
139
    DBEditEBt: TDBEdit;
140
    DBEditEDc: TDBEdit;
141
    DBEditEDt: TDBEdit;
142
    DBEditEMc: TDBEdit;
143
    DBEditEMt: TDBEdit;
144
    DBEditENc: TDBEdit;
145
    DBEditENt: TDBEdit;
146
    DBEditEDt_EDc: TDBEdit;
147
    DBEditEMt_EMc: TDBEdit;
148
    DBEditENt_ENc: TDBEdit;
149
    ValidateEditEBt_EBc: TJvValidateEdit;
150
    GroupBoxEnergyUtilization: TGroupBox;
151
    LabeldE: TLabel;
152
    LabelEM_ED: TLabel;
153
    LabelEN_EM: TLabel;
154
    LabelCrois2: TLabel;
155
    LabelTruie2: TLabel;
156
    LabelBonus: TLabel;
157
    LabelLysd_EN: TLabel;
158
    DBEditdEc: TDBEdit;
159
    DBEditdEt: TDBEdit;
160
    DBEditEMc_EDc: TDBEdit;
161
    DBEditEMt_EDt: TDBEdit;
162
    DBEditENc_EMc: TDBEdit;
163
    DBEditENt_EMt: TDBEdit;
164
    DBEditBonus: TDBEdit;
165
    DBEditLysd_ENc: TDBEdit;
166
    DBEditLysd_ENt: TDBEdit;
167
    GroupBoxMinerals: TGroupBox;
168
    LabelCa: TLabel;
169
    LabelP: TLabel;
170
    LabelDigP: TLabel;
171
    LabelFarine: TLabel;
172
    LabelGranule: TLabel;
173
    LabeldP: TLabel;
174
    DBEditCa: TDBEdit;
175
    DBEditP: TDBEdit;
176
    DBEditdPphy: TDBEdit;
177
    DBEditdP: TDBEdit;
178
    GroupBoxProximal: TGroupBox;
179
    LabelMAT: TLabel;
180
    LabelCB: TLabel;
181
    LabelMG: TLabel;
182
    LabelMM: TLabel;
183
    LabelNDF: TLabel;
184
    LabelADF: TLabel;
185
    LabelADL: TLabel;
186
    LabelAmidon: TLabel;
187
    LabelSucres: TLabel;
188
    DBEditMAT: TDBEdit;
189
    DBEditCB: TDBEdit;
190
    DBEditMG: TDBEdit;
191
    DBEditMM: TDBEdit;
192
    DBEditNDF: TDBEdit;
193
    DBEditADF: TDBEdit;
194
    DBEditADL: TDBEdit;
195
    DBEditAmidon: TDBEdit;
196
    DBEditSucres: TDBEdit;
197
    JvImgBtnModify: TJvImgBtn;
198
    JvImgBtnDelete: TJvImgBtn;
199
    JvImgBtnPrint: TJvImgBtn;
200
    JvImgBtnXML: TJvImgBtn;
201
    JvImgBtnHelp: TJvImgBtn;
202
    JvImgBtnClose: TJvImgBtn;
203
    PanelHead: TPanel;
204 2 avalancogn
    DBEditNa: TDBEdit;
205
    LabelNa: TLabel;
206
    DBEditK: TDBEdit;
207
    LabelK: TLabel;
208
    DBEditCl: TDBEdit;
209
    LabelCl: TLabel;
210
    DBEditBE: TDBEdit;
211
    LabelBE: TLabel;
212 1 avalancogn
    procedure FormCreate(Sender: TObject);
213
    procedure FormShow(Sender: TObject);
214
    procedure ActionModifyExecute(Sender: TObject);
215
    procedure ActionDeleteExecute(Sender: TObject);
216
    procedure ActionPrintExecute(Sender: TObject);
217
    procedure ActionXMLExecute(Sender: TObject);
218
    procedure ActionHelpExecute(Sender: TObject);
219
    procedure ActionCloseExecute(Sender: TObject);
220
  private
221
    { D?clarations priv?es }
222
    procedure BuildReport;
223
    procedure EditEmpty(Edit: TJvValidateEdit);
224
    procedure EditShadow(Edit: TDBEdit);
225
  public
226
    { D?clarations publiques }
227
  end;
228
229
var
230
  FormIngredientDetail: TFormIngredientDetail;
231
232
implementation
233
234
{$R *.dfm}
235
236
uses
237
  UnitDeclaration, UnitOptions, UnitIngredientEditionCopy, UnitIngredientEditionOriginal;
238
239
procedure TFormIngredientDetail.ActionCloseExecute(Sender: TObject);
240
begin
241
  ModalResult := mrClose;
242
end;
243
244
procedure TFormIngredientDetail.ActionXMLExecute(Sender: TObject);
245
var
246
  i: Integer;
247
  USFormatSettings: TFormatSettings;
248
  XMLDoc: IXMLDocument;
249
  Workbook, Worksheet, Table, Row: IXMLNode;
250
251
  procedure CellData(Row: IXMLNode; Value, Format: string);
252
  var
253
    Cell, Data: IXMLNode;
254
  begin
255
    Cell := Row.AddChild('Cell');
256
    Data := Cell.AddChild('Data');
257
    Data.Attributes['ss:Type'] := Format;
258
    Data.Text := Value;
259
  end;
260
261
begin
262
  if SaveDialogExport.Execute
263
  then
264
  begin
265
    GetLocaleFormatSettings(1033, USFormatSettings);
266
    XMLDoc := TXMLDocument.Create(nil);
267
    try
268
      XMLDoc.XML.Clear;
269
      XMLDoc.XML.Add('<?xml version="1.0" encoding="UTF-8"?>');
270
      XMLDoc.XML.Add('<?mso-application progid="Excel.Sheet"?>');
271
      XMLDoc.XML.Add('<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet">');
272
      XMLDoc.XML.Add('</Workbook>');
273
      XMLDoc.Active := True;
274
      Workbook := XMLDoc.DocumentElement;
275
      Workbook.DeclareNamespace('o', 'urn:schemas-microsoft-com:office:office');
276
      Workbook.DeclareNamespace('x', 'urn:schemas-microsoft-com:office:excel');
277
      Workbook.DeclareNamespace('ss', 'urn:schemas-microsoft-com:office:spreadsheet');
278
      Workbook.DeclareNamespace('html', 'http://www.w3.org/TR/REC-html40');
279
      Worksheet := Workbook.AddChild('Worksheet');
280
      Worksheet.SetAttributeNS('ss:Name', Workbook.FindNamespaceURI('ss'), Caption);
281
      Table := Worksheet.AddChild('Table');
282
      // Titre
283
      Row := Table.AddChild('Row');
284
      CellData(Row, _('Label'), 'String');
285
      CellData(Row, _('Value'), 'String');
286
      CellData(Row, _('Unit'), 'String');
287
      // Donn?es
288
      with DataModuleDeclaration do
289
        for i := 0 to ClientDataSetIngredients.FieldCount - 1 do
290
          if not (i in [0, 2, 3, 5, 6, 9, 58..77, 78..97])
291
          then // Champs export?s
292
          begin
293
            Row := Table.AddChild('Row');
294
            // Label
295
            CellData(Row, _(ClientDataSetIngredients.Fields[i].DisplayLabel), 'String');
296
            // Value
297
            case i of
298
              1, 4, 7:
299
                CellData(Row, ClientDataSetIngredients.Fields[i].AsWideString, 'String');
300
              8, 10..18:
301
                if not ClientDataSetIngredients.Fields[i].IsNull
302
                then
303
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
304
                else
305
                  CellData(Row, '', 'String');
306
              19, 22, 24, 26, 28, 30, 32:
307
                if not ClientDataSetIngredients.Fields[i].IsNull
308
                then
309
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
310
                else
311
                  CellData(Row, '', 'String');
312 4 avalancogn
              20, 21, 23, 25, 27, 29, 31, 33..37:
313 1 avalancogn
                if not ClientDataSetIngredients.Fields[i].IsNull
314
                then
315
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, 1, USFormatSettings), 'Number')
316
                else
317
                  CellData(Row, '', 'String');
318
              38..57, 98..117:
319
                if not ClientDataSetIngredients.Fields[i].IsNull
320
                then
321
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, FormOptions.AADecimals, USFormatSettings), 'Number')
322
                else
323
                  CellData(Row, '', 'String');
324
              118..119:
325
                if not ClientDataSetIngredients.Fields[i].IsNull
326
                then
327
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, 2, USFormatSettings), 'Number')
328
                else
329
                  CellData(Row, '', 'String');
330 4 avalancogn
              120..124:
331 1 avalancogn
                if not ClientDataSetIngredients.Fields[i].IsNull
332
                then
333
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, FormOptions.MineralsDecimals, USFormatSettings), 'Number')
334
                else
335
                  CellData(Row, '', 'String');
336 4 avalancogn
              125:
337
                if not ClientDataSetIngredients.Fields[i].IsNull
338
                then
339
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, 2, USFormatSettings), 'Number')
340
                else
341
                  CellData(Row, '', 'String');
342
              126..127:
343
                if not ClientDataSetIngredients.Fields[i].IsNull
344
                then
345
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, 1, USFormatSettings), 'Number')
346
                else
347
                  CellData(Row, '', 'String');
348 1 avalancogn
            end;
349
            // Unit
350
            case i of
351
              8: // MS
352
                CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String');
353
              10..18: // Analyse proximale
354
                if FormOptions.Expression = 0
355
                then // sur frais
356
                  CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
357
                else // sur mati?re s?che
358
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
359
              19, 22, 24, 26, 28, 30, 32: // Energie
360
                if FormOptions.Expression = 0
361
                then // sur frais
362
                  CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
363
                else // sur mati?re s?che
364
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
365 4 avalancogn
              20, 21, 23, 25, 27, 29, 31, 33..37, 126..127: // %
366 1 avalancogn
                CellData(Row, '%', 'String');
367
              38..57, 98..117: // AA
368
                if FormOptions.Expression = 0
369
                then // sur frais
370
                  CellData(Row, FormOptions.ComboBoxAA.Items[FormOptions.AA], 'String')
371
                else // sur mati?re s?che
372
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxAA.Items[FormOptions.AA], _('DM')]), 'String');
373
              118..119: // Lysd/EN
374
                if FormOptions.Energy = 0
375
                then // MJ
376
                  CellData(Row, _('g/MJ'), 'String')
377
                else // kcal
378
                  CellData(Row, _('g/1000kcal'), 'String');
379 4 avalancogn
              120..124: // Min?raux
380 1 avalancogn
                if FormOptions.Expression = 0
381
                then // sur frais
382
                  CellData(Row, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], 'String')
383
                else // sur mati?re s?che
384
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], _('DM')]), 'String');
385 4 avalancogn
              125: // %
386
                if FormOptions.Expression = 0
387
                then // sur frais
388
                  CellData(Row, _('mEq/kg'), 'String')
389
                else // sur mati?re s?che
390
                  CellData(Row, Format('%s %s', [_('mEq/kg'), _('DM')]), 'String');
391 1 avalancogn
            end;
392
          end;
393
      XMLDoc.SaveToFile(SaveDialogExport.FileName);
394
      XmlDoc.Active := False;
395
    finally
396
      XMLDoc := nil;
397
    end;
398
  end;
399
end;
400
401
procedure TFormIngredientDetail.ActionDeleteExecute(Sender: TObject);
402
var
403
  UserName: String;
404
begin
405
  with DataModuleDeclaration do
406
  begin
407
    ClientDataSetComposition.Filter := Format('Ingredient = %d and User', [ClientDataSetIngredientsId.Value]);
408
    ClientDataSetComposition.Filtered := True;
409
    try
410
      if ClientDataSetComposition.RecordCount > 0
411
      then
412
        MessageDlg(_('This ingredient is used in a diet.') + sLineBreak + _('You cannot delete it.'), mtError, [mbOK], 0)
413
      else
414
        if MessageDlg(_('Are sure you want to delete this record?') + sLineBreak + _('This action could not be canceled.'), mtConfirmation, [mbYes, mbNo], 0) = mrYes
415
        then
416
        begin
417
          ClientDataSetIngredients.DisableControls;
418
          try
419
            UserName := ClientDataSetIngredientsName.Value;
420
            // Suprimer la mati?re premi?re
421
            DBUser.BeginTransaction;
422
            try
423
              DBUser.ExecSQL('DELETE FROM Ingredients '
424
                + Format('WHERE Id = %d', [ClientDataSetIngredientsId.Value]));
425
              DBUser.Commit;
426
            except
427
              DBUser.RollBack;
428
              MessageDlg(Format(_('Unknown error: %s %s %s'), ['UnitIngredientDetail', 'ActionDeleteExecute', 'DBUser (DELETE FROM Ingredients)']), mtError, [mbOK], 0);
429
              Exit;
430
            end;
431
            // Suprimer de ClientDataSetIngredients
432
            ClientDataSetIngredients.Delete;
433
            // Suprimer le nom de la liste des mati?res premi?res utilisateur
434
            UserList.Delete(UserList.IndexOf(UserName));
435
            // Fermer la fen?tre
436
            Close;
437
          finally
438
            ClientDataSetIngredients.EnableControls;
439
          end;
440
        end;
441
    finally
442
      ClientDataSetComposition.Filtered := False;
443
      ClientDataSetComposition.Filter := '';
444
    end;
445
  end;
446
end;
447
448
procedure TFormIngredientDetail.ActionHelpExecute(Sender: TObject);
449
begin
450
  Application.HelpContext(HelpContext);
451
end;
452
453
procedure TFormIngredientDetail.ActionModifyExecute(Sender: TObject);
454
begin
455
  if DataModuleDeclaration.ClientDataSetIngredientsModel.IsNull
456
  then // Cr?ation originale
457
  begin
458
    FormIngredientEditionOriginal := TFormIngredientEditionOriginal.Create(nil);
459
    try
460
      FormIngredientEditionOriginal.ShowModal;
461
    finally
462
      FormIngredientEditionOriginal.Release;
463
    end;
464
  end
465
  else // Copie des tables de r?f?rence
466
  begin
467
    FormIngredientEditionCopy := TFormIngredientEditionCopy.Create(nil);
468
    try
469
      FormIngredientEditionCopy.ShowModal;
470
    finally
471
      FormIngredientEditionCopy.Release;
472
    end;
473
  end;
474
//  with DataModuleDeclaration do
475
//    Hint := ClientDataSetIngredientsDefinition.Value;
476
end;
477
478
procedure TFormIngredientDetail.ActionPrintExecute(Sender: TObject);
479
begin
480
  if RpDev.PrinterSetupDialog
481
  then
482
  begin
483
    RvSystemReport.DoNativeOutput := False;
484
    RvSystemReport.DefaultDest := rdPrinter;
485
    RvSystemReport.RenderObject := nil;
486
    RvSystemReport.OutputFileName := '';
487
    RvProjectReport.Open;
488
    BuildReport;
489
    with DataModuleDeclaration do
490
      if ClientDataSetIngredientsUser.Value
491
      then // User
492
        TableIngredients.Free;
493
    RvProjectReport.Execute;
494
    Application.ProcessMessages;
495
    RvProjectReport.Close;
496
  end;
497
end;
498
499
procedure TFormIngredientDetail.BuildReport;
500
var
501
  i: Integer;
502
  Page: TRavePage;
503
begin
504
  with DataModuleDeclaration do
505
    if ClientDataSetIngredientsUser.Value
506
    then // User
507
      TableIngredients := DBUser.GetTable('SELECT * FROM Ingredients '
508
        + Format('WHERE Id = %d', [ClientDataSetIngredientsId.Value]));
509
  with DataModuleDeclaration do
510
    if ClientDataSetIngredients.Eof
511
    then // Bug : seconde page blanche
512
      if ClientDataSetIngredients.RecordCount > 1
513
      then
514
      begin
515
        ClientDataSetIngredients.Prior;
516
        ClientDataSetIngredients.Next;
517
      end
518
      else
519
        ClientDataSetIngredients.First;
520
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportIngredient.PageIngredient1', nil) as TRavePage;
521
  for i := 0 to Page.ComponentCount - 1 do
522
  begin
523
    if Page.Components[i].ClassNameIs('TRaveText')
524
    then // Traduire
525
    begin
526
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
527
      then
528
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
529
      TranslateComponent(Page.Components[i]);
530
      if (Page.Components[i] as TRaveText).Name = 'TextMS'
531
      then
532
        with FormOptions do
533
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, ComboBoxProximal.Items[Proximal]]);
534
      if (Page.Components[i] as TRaveText).Name = 'TextUnitProximal'
535
      then
536
        with FormOptions do
537
          if Expression = 0
538
          then // sur frais
539
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxProximal.Items[Proximal]])
540
          else // sur mati?re s?che
541
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxProximal.Items[Proximal], _('DM')]);
542
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyC'
543
      then
544
        with FormOptions do
545
          if Expression = 0
546
          then // sur frais
547
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxEnergy.Items[Energy]])
548
          else // sur mati?re s?che
549
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxEnergy.Items[Energy], _('DM')]);
550
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyT'
551
      then
552
        with FormOptions do
553
          if Expression = 0
554
          then // sur frais
555
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxEnergy.Items[Energy]])
556
          else // sur mati?re s?che
557
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxEnergy.Items[Energy], _('DM')]);
558
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyRatio'
559
      then
560
        (Page.Components[i] as TRaveText).Text := '(%)';
561
      if (Page.Components[i] as TRaveText).Name = 'TextEBt_EBc'
562
      then
563
        (Page.Components[i] as TRaveText).Text := ValidateEditEBt_EBc.Text;
564
      if (Page.Components[i] as TRaveText).Name = 'TextdE'
565
      then
566
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
567
      if (Page.Components[i] as TRaveText).Name = 'TextME_DE'
568
      then
569
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
570
      if (Page.Components[i] as TRaveText).Name = 'TextNE_ME'
571
      then
572
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
573
    end;
574
    if Page.Components[i].ClassNameIs('TRaveDataMemo') and (Screen.Fonts.IndexOf('Arial Unicode MS') <> -1)
575
    then
576
      (Page.Components[i] as TRaveDataMemo).Font.Name := 'Arial Unicode MS';
577
    if Page.Components[i].ClassNameIs('TRaveDataText')
578
    then
579
    begin
580
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
581
      then
582
        (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
583
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextMM'
584
      then
585
        with DataModuleDeclaration do
586
          if ClientDataSetIngredientsUser.Value
587
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
588
          then // Valeur h?rit?e du mod?le
589
          begin
590
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
591
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
592
          end;
593
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextMAT'
594
      then
595
        with DataModuleDeclaration do
596
          if ClientDataSetIngredientsUser.Value
597
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
598
          then // Valeur h?rit?e du mod?le
599
          begin
600
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
601
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
602
          end;
603
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextMG'
604
      then
605
        with DataModuleDeclaration do
606
          if ClientDataSetIngredientsUser.Value
607
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
608
          then // Valeur h?rit?e du mod?le
609
          begin
610
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
611
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
612
          end;
613
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextCB'
614
      then
615
        with DataModuleDeclaration do
616
          if ClientDataSetIngredientsUser.Value
617
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
618
          then // Valeur h?rit?e du mod?le
619
          begin
620
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
621
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
622
          end;
623
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextNDF'
624
      then
625
        with DataModuleDeclaration do
626
          if ClientDataSetIngredientsUser.Value
627
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
628
          then // Valeur h?rit?e du mod?le
629
          begin
630
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
631
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
632
          end;
633
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextADF'
634
      then
635
        with DataModuleDeclaration do
636
          if ClientDataSetIngredientsUser.Value
637
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
638
          then // Valeur h?rit?e du mod?le
639
          begin
640
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
641
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
642
          end;
643
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextADL'
644
      then
645
        with DataModuleDeclaration do
646
          if ClientDataSetIngredientsUser.Value
647
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
648
          then // Valeur h?rit?e du mod?le
649
          begin
650
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
651
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
652
          end;
653
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextAmidon'
654
      then
655
        with DataModuleDeclaration do
656
          if ClientDataSetIngredientsUser.Value
657
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
658
          then // Valeur h?rit?e du mod?le
659
          begin
660
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
661
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
662
          end;
663
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextSucres'
664
      then
665
        with DataModuleDeclaration do
666
          if ClientDataSetIngredientsUser.Value
667
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
668
          then // Valeur h?rit?e du mod?le
669
          begin
670
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
671
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
672
          end;
673
    end;
674
  end;
675
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportIngredient.PageIngredient2', nil) as TRavePage;
676
  for i := 0 to Page.ComponentCount - 1 do
677
  begin
678
    if Page.Components[i].ClassNameIs('TRaveText')
679
    then // Traduire
680
    begin
681
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
682
      then
683
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
684
      TranslateComponent(Page.Components[i]);
685
      if (Page.Components[i] as TRaveText).Name = 'TextdN'
686
      then
687
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
688
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAATot'
689
      then
690
        with FormOptions do
691
          if Expression = 0
692
          then // sur frais
693
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxAA.Items[AA]])
694
          else // sur mati?re s?che
695
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxAA.Items[AA], _('DM')]);
696
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAADig'
697
      then
698
        with FormOptions do
699
          if Expression = 0
700
          then // sur frais
701
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxAA.Items[AA]])
702
          else // sur mati?re s?che
703
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxAA.Items[AA], _('DM')]);
704
      if (Page.Components[i] as TRaveText).Name = 'TextUnitLysd_EN'
705
      then
706
        if FormOptions.Energy = 0
707
        then // MJ
708
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/MJ')])
709
        else // kcal
710
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/1000kcal')]);
711
      if (Page.Components[i] as TRaveText).Name = 'TextUnitMinerals'
712
      then
713
        with FormOptions do
714
          if Expression = 0
715
          then // sur frais
716
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxMinerals.Items[Minerals]])
717
          else // sur mati?re s?che
718
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxMinerals.Items[Minerals], _('DM')]);
719
      if (Page.Components[i] as TRaveText).Name = 'TextdP'
720
      then
721
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
722
    end;
723
    if Page.Components[i].ClassNameIs('TRaveDataText')
724
    then
725
    begin
726
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
727
      then
728
        (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
729
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextCa'
730
      then
731
        with DataModuleDeclaration do
732
          if ClientDataSetIngredientsUser.Value
733
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
734
          then // Valeur h?rit?e du mod?le
735
          begin
736
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
737
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
738
          end;
739
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextP'
740
      then
741
        with DataModuleDeclaration do
742
          if ClientDataSetIngredientsUser.Value
743
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
744
          then // Valeur h?rit?e du mod?le
745
          begin
746
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
747
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
748
          end;
749 3 avalancogn
(*
750
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextNa'
751
      then
752
        with DataModuleDeclaration do
753
          if ClientDataSetIngredientsUser.Value
754
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Na'])
755
          then // Valeur h?rit?e du mod?le
756
          begin
757
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
758
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
759
          end;
760
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextK'
761
      then
762
        with DataModuleDeclaration do
763
          if ClientDataSetIngredientsUser.Value
764
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['K'])
765
          then // Valeur h?rit?e du mod?le
766
          begin
767
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
768
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
769
          end;
770
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextCl'
771
      then
772
        with DataModuleDeclaration do
773
          if ClientDataSetIngredientsUser.Value
774
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cl'])
775
          then // Valeur h?rit?e du mod?le
776
          begin
777
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
778
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
779
          end;
780
*)
781 1 avalancogn
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextdP'
782
      then
783
        with DataModuleDeclaration do
784
          if ClientDataSetIngredientsUser.Value
785
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
786
          then // Valeur h?rit?e du mod?le
787
          begin
788
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
789
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
790
          end;
791
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextdPphy'
792
      then
793
        with DataModuleDeclaration do
794
          if ClientDataSetIngredientsUser.Value
795
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
796
          then // Valeur h?rit?e du mod?le
797
          begin
798
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
799
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
800
          end;
801
    end;
802
  end;
803
end;
804
805
procedure TFormIngredientDetail.EditEmpty(Edit: TJvValidateEdit);
806
begin
807
  Edit.DisplayFormat := dfNone;
808
  Edit.Value := '';
809
end;
810
811
procedure TFormIngredientDetail.EditShadow(Edit: TDBEdit);
812
begin
813
  Edit.Font.Style := Edit.Font.Style + [fsItalic];
814
  Edit.Font.Color := cl3DDkShadow;
815
end;
816
817
procedure TFormIngredientDetail.FormCreate(Sender: TObject);
818
var
819
  ProximalUnit, EnergyUnit, AAUnit, MineralsUnit: String;
820
begin
821
  if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
822
  then
823
    Font.Name := 'Arial Unicode MS';
824
//  PanelButtons.Font.Size := PanelButtons.Font.Size + 2;
825
  PanelButtons.Font.Style := [fsBold];
826
  LabelName.Font.Style := [fsBold];
827
  DBEditName.Font.Style := [fsBold];
828
  TranslateComponent(Self);
829
  with FormOptions do
830 2 avalancogn
    LabelMS.Caption := Format('%s (%s)', [LabelMS.Caption, ComboBoxProximal.Items[Proximal]]);
831
  with FormOptions do
832 1 avalancogn
    if Expression = 0
833
    then // sur frais
834
    begin
835
      ProximalUnit := ComboBoxProximal.Items[Proximal];
836
      EnergyUnit := ComboBoxEnergy.Items[Energy];
837
      AAUnit := ComboBoxAA.Items[AA];
838
      MineralsUnit := ComboBoxMinerals.Items[Minerals];
839
    end
840
    else // sur mati?re s?che
841
    begin
842
      ProximalUnit := Format('%s %s', [ComboBoxProximal.Items[Proximal], _('DM')]);
843
      EnergyUnit := Format('%s %s', [ComboBoxEnergy.Items[Energy], _('DM')]);
844
      AAUnit := Format('%s %s', [ComboBoxAA.Items[AA], _('DM')]);
845
      MineralsUnit := Format('%s %s', [ComboBoxMinerals.Items[Minerals], _('DM')]);
846
    end;
847
  GroupBoxProximal.Caption := Format('%s (%s)', [GroupBoxProximal.Caption, ProximalUnit]);
848 3 avalancogn
  GroupBoxMinerals.Caption := Format('%s (%s)', [GroupBoxMinerals.Caption, MineralsUnit]);
849
  if FormOptions.Expression = 0
850
  then // sur frais
851
    LabelBE.Caption := Format('%s (%s)', [LabelBE.Caption, _('mEq/kg')])
852
  else // sur mati?re s?che
853
    LabelBE.Caption := Format('%s (%s %s)', [LabelBE.Caption, _('mEq/kg'), _('DM')]);
854
  LabelDigP.Caption := Format('%s (%%)', [LabelDigP.Caption]);
855 1 avalancogn
  GroupBoxEnergy.Caption := Format('%s (%s)', [GroupBoxEnergy.Caption, EnergyUnit]);
856
  LabelRatio.Caption := Format('%s (%%)', [LabelRatio.Caption]);
857
  GroupBoxEnergyUtilization.Caption := Format('%s (%%)', [GroupBoxEnergyUtilization.Caption]);
858 2 avalancogn
//  GroupBoxAzote.Caption := Format('%s (%%)', [GroupBoxAzote.Caption]);
859
  LabeldN.Caption := Format('%s (%%)', [LabeldN.Caption]);
860 1 avalancogn
  if FormOptions.Energy = 0
861
  then // MJ
862
    LabelLysd_EN.Caption := Format('%s (%s)', [LabelLysd_EN.Caption, _('g/MJ')])
863
  else // kcal
864
    LabelLysd_EN.Caption := Format('%s (%s)', [LabelLysd_EN.Caption, _('g/1000kcal')]);
865
  GroupBoxAA.Caption := Format('%s (%s)', [GroupBoxAA.Caption, AAUnit]);
866
  LabeldAA.Caption := Format('%s (%%)', [LabeldAA.Caption]);
867
end;
868
869
procedure TFormIngredientDetail.FormShow(Sender: TObject);
870
begin
871
  with DataModuleDeclaration do
872
  begin
873
    if ClientDataSetIngredientsEB.IsNull
874
    then
875
      EditEmpty(ValidateEditEBt_EBc)
876
    else
877
      ValidateEditEBt_EBc.Value := 100;
878
    if ClientDataSetIngredientsUser.Value
879
    then // Mati?re premi?re utilisateur
880
    begin
881
      TableIngredients := DBUser.GetTable('SELECT * FROM Ingredients '
882
        + Format('WHERE Id = %d', [ClientDataSetIngredientsId.Value]));
883
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
884
      then // Valeur h?rit?e du mod?le
885
        EditShadow(DBEditMM);
886
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
887
      then // Valeur h?rit?e du mod?le
888
        EditShadow(DBEditMAT);
889
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
890
      then // Valeur h?rit?e du mod?le
891
        EditShadow(DBEditMG);
892
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
893
      then // Valeur h?rit?e du mod?le
894
        EditShadow(DBEditCB);
895
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
896
      then // Valeur h?rit?e du mod?le
897
        EditShadow(DBEditNDF);
898
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
899
      then // Valeur h?rit?e du mod?le
900
        EditShadow(DBEditADF);
901
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
902
      then // Valeur h?rit?e du mod?le
903
        EditShadow(DBEditADL);
904
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
905
      then // Valeur h?rit?e du mod?le
906
        EditShadow(DBEditAmidon);
907
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
908
      then // Valeur h?rit?e du mod?le
909
        EditShadow(DBEditSucres);
910
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
911
      then // Valeur h?rit?e du mod?le
912
        EditShadow(DBEditCa);
913
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
914
      then // Valeur h?rit?e du mod?le
915
        EditShadow(DBEditP);
916 3 avalancogn
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Na'])
917
      then // Valeur h?rit?e du mod?le
918
        EditShadow(DBEditNa);
919
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['K'])
920
      then // Valeur h?rit?e du mod?le
921
        EditShadow(DBEditK);
922
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cl'])
923
      then // Valeur h?rit?e du mod?le
924
        EditShadow(DBEditCl);
925 1 avalancogn
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
926
      then // Valeur h?rit?e du mod?le
927
        EditShadow(DBEditdPphy);
928
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
929
      then // Valeur h?rit?e du mod?le
930
        EditShadow(DBEditdP);
931
      TableIngredients.Free;
932
    end
933
    else // Mati?re premi?re de r?f?rence
934
    begin
935
      JvImgBtnModify.Enabled := False;
936
      JvImgBtnDelete.Enabled := False;
937
    end;
938
  end;
939
end;
940
941
end.