Statistiques
| Révision:

root / UnitIngredientDetail.pas @ 15

Historique | Voir | Annoter | Télécharger (37,451 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 5 avalancogn
    LabelBEUnit: TLabel;
213 1 avalancogn
    procedure FormCreate(Sender: TObject);
214
    procedure FormShow(Sender: TObject);
215
    procedure ActionModifyExecute(Sender: TObject);
216
    procedure ActionDeleteExecute(Sender: TObject);
217
    procedure ActionPrintExecute(Sender: TObject);
218
    procedure ActionXMLExecute(Sender: TObject);
219
    procedure ActionHelpExecute(Sender: TObject);
220
    procedure ActionCloseExecute(Sender: TObject);
221
  private
222
    { D?clarations priv?es }
223
    procedure BuildReport;
224
    procedure EditEmpty(Edit: TJvValidateEdit);
225
    procedure EditShadow(Edit: TDBEdit);
226
  public
227
    { D?clarations publiques }
228
  end;
229
230
var
231
  FormIngredientDetail: TFormIngredientDetail;
232
233
implementation
234
235
{$R *.dfm}
236
237
uses
238
  UnitDeclaration, UnitOptions, UnitIngredientEditionCopy, UnitIngredientEditionOriginal;
239
240
procedure TFormIngredientDetail.ActionCloseExecute(Sender: TObject);
241
begin
242
  ModalResult := mrClose;
243
end;
244
245
procedure TFormIngredientDetail.ActionXMLExecute(Sender: TObject);
246
var
247
  i: Integer;
248
  USFormatSettings: TFormatSettings;
249
  XMLDoc: IXMLDocument;
250
  Workbook, Worksheet, Table, Row: IXMLNode;
251
252
  procedure CellData(Row: IXMLNode; Value, Format: string);
253
  var
254
    Cell, Data: IXMLNode;
255
  begin
256
    Cell := Row.AddChild('Cell');
257
    Data := Cell.AddChild('Data');
258
    Data.Attributes['ss:Type'] := Format;
259
    Data.Text := Value;
260
  end;
261
262
begin
263
  if SaveDialogExport.Execute
264
  then
265
  begin
266
    GetLocaleFormatSettings(1033, USFormatSettings);
267
    XMLDoc := TXMLDocument.Create(nil);
268
    try
269
      XMLDoc.XML.Clear;
270
      XMLDoc.XML.Add('<?xml version="1.0" encoding="UTF-8"?>');
271
      XMLDoc.XML.Add('<?mso-application progid="Excel.Sheet"?>');
272
      XMLDoc.XML.Add('<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet">');
273
      XMLDoc.XML.Add('</Workbook>');
274
      XMLDoc.Active := True;
275
      Workbook := XMLDoc.DocumentElement;
276
      Workbook.DeclareNamespace('o', 'urn:schemas-microsoft-com:office:office');
277
      Workbook.DeclareNamespace('x', 'urn:schemas-microsoft-com:office:excel');
278
      Workbook.DeclareNamespace('ss', 'urn:schemas-microsoft-com:office:spreadsheet');
279
      Workbook.DeclareNamespace('html', 'http://www.w3.org/TR/REC-html40');
280
      Worksheet := Workbook.AddChild('Worksheet');
281
      Worksheet.SetAttributeNS('ss:Name', Workbook.FindNamespaceURI('ss'), Caption);
282
      Table := Worksheet.AddChild('Table');
283
      // Titre
284
      Row := Table.AddChild('Row');
285
      CellData(Row, _('Label'), 'String');
286
      CellData(Row, _('Value'), 'String');
287
      CellData(Row, _('Unit'), 'String');
288
      // Donn?es
289
      with DataModuleDeclaration do
290
        for i := 0 to ClientDataSetIngredients.FieldCount - 1 do
291
          if not (i in [0, 2, 3, 5, 6, 9, 58..77, 78..97])
292
          then // Champs export?s
293
          begin
294
            Row := Table.AddChild('Row');
295
            // Label
296
            CellData(Row, _(ClientDataSetIngredients.Fields[i].DisplayLabel), 'String');
297
            // Value
298
            case i of
299
              1, 4, 7:
300
                CellData(Row, ClientDataSetIngredients.Fields[i].AsWideString, 'String');
301
              8, 10..18:
302
                if not ClientDataSetIngredients.Fields[i].IsNull
303
                then
304
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
305
                else
306
                  CellData(Row, '', 'String');
307
              19, 22, 24, 26, 28, 30, 32:
308
                if not ClientDataSetIngredients.Fields[i].IsNull
309
                then
310
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
311
                else
312
                  CellData(Row, '', 'String');
313 4 avalancogn
              20, 21, 23, 25, 27, 29, 31, 33..37:
314 1 avalancogn
                if not ClientDataSetIngredients.Fields[i].IsNull
315
                then
316
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, 1, USFormatSettings), 'Number')
317
                else
318
                  CellData(Row, '', 'String');
319
              38..57, 98..117:
320
                if not ClientDataSetIngredients.Fields[i].IsNull
321
                then
322
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, FormOptions.AADecimals, USFormatSettings), 'Number')
323
                else
324
                  CellData(Row, '', 'String');
325
              118..119:
326
                if not ClientDataSetIngredients.Fields[i].IsNull
327
                then
328
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, 2, USFormatSettings), 'Number')
329
                else
330
                  CellData(Row, '', 'String');
331 4 avalancogn
              120..124:
332 1 avalancogn
                if not ClientDataSetIngredients.Fields[i].IsNull
333
                then
334
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, FormOptions.MineralsDecimals, USFormatSettings), 'Number')
335
                else
336
                  CellData(Row, '', 'String');
337 5 avalancogn
              125..127:
338 4 avalancogn
                if not ClientDataSetIngredients.Fields[i].IsNull
339
                then
340
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, 1, USFormatSettings), 'Number')
341
                else
342
                  CellData(Row, '', 'String');
343 1 avalancogn
            end;
344
            // Unit
345
            case i of
346
              8: // MS
347
                CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String');
348
              10..18: // Analyse proximale
349
                if FormOptions.Expression = 0
350
                then // sur frais
351
                  CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
352
                else // sur mati?re s?che
353
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
354
              19, 22, 24, 26, 28, 30, 32: // Energie
355
                if FormOptions.Expression = 0
356
                then // sur frais
357
                  CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
358
                else // sur mati?re s?che
359
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
360 4 avalancogn
              20, 21, 23, 25, 27, 29, 31, 33..37, 126..127: // %
361 1 avalancogn
                CellData(Row, '%', 'String');
362
              38..57, 98..117: // AA
363
                if FormOptions.Expression = 0
364
                then // sur frais
365
                  CellData(Row, FormOptions.ComboBoxAA.Items[FormOptions.AA], 'String')
366
                else // sur mati?re s?che
367
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxAA.Items[FormOptions.AA], _('DM')]), 'String');
368
              118..119: // Lysd/EN
369
                if FormOptions.Energy = 0
370
                then // MJ
371
                  CellData(Row, _('g/MJ'), 'String')
372
                else // kcal
373
                  CellData(Row, _('g/1000kcal'), 'String');
374 4 avalancogn
              120..124: // Min?raux
375 1 avalancogn
                if FormOptions.Expression = 0
376
                then // sur frais
377
                  CellData(Row, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], 'String')
378
                else // sur mati?re s?che
379
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], _('DM')]), 'String');
380 5 avalancogn
              125: // Bilan ?lectrolytique
381 4 avalancogn
                if FormOptions.Expression = 0
382
                then // sur frais
383
                  CellData(Row, _('mEq/kg'), 'String')
384
                else // sur mati?re s?che
385
                  CellData(Row, Format('%s %s', [_('mEq/kg'), _('DM')]), 'String');
386 1 avalancogn
            end;
387
          end;
388
      XMLDoc.SaveToFile(SaveDialogExport.FileName);
389
      XmlDoc.Active := False;
390
    finally
391
      XMLDoc := nil;
392
    end;
393
  end;
394
end;
395
396
procedure TFormIngredientDetail.ActionDeleteExecute(Sender: TObject);
397
var
398
  UserName: String;
399
begin
400
  with DataModuleDeclaration do
401
  begin
402
    ClientDataSetComposition.Filter := Format('Ingredient = %d and User', [ClientDataSetIngredientsId.Value]);
403
    ClientDataSetComposition.Filtered := True;
404
    try
405
      if ClientDataSetComposition.RecordCount > 0
406
      then
407
        MessageDlg(_('This ingredient is used in a diet.') + sLineBreak + _('You cannot delete it.'), mtError, [mbOK], 0)
408
      else
409
        if MessageDlg(_('Are sure you want to delete this record?') + sLineBreak + _('This action could not be canceled.'), mtConfirmation, [mbYes, mbNo], 0) = mrYes
410
        then
411
        begin
412
          ClientDataSetIngredients.DisableControls;
413
          try
414
            UserName := ClientDataSetIngredientsName.Value;
415
            // Suprimer la mati?re premi?re
416
            DBUser.BeginTransaction;
417
            try
418
              DBUser.ExecSQL('DELETE FROM Ingredients '
419
                + Format('WHERE Id = %d', [ClientDataSetIngredientsId.Value]));
420
              DBUser.Commit;
421
            except
422
              DBUser.RollBack;
423
              MessageDlg(Format(_('Unknown error: %s %s %s'), ['UnitIngredientDetail', 'ActionDeleteExecute', 'DBUser (DELETE FROM Ingredients)']), mtError, [mbOK], 0);
424
              Exit;
425
            end;
426
            // Suprimer de ClientDataSetIngredients
427
            ClientDataSetIngredients.Delete;
428
            // Suprimer le nom de la liste des mati?res premi?res utilisateur
429
            UserList.Delete(UserList.IndexOf(UserName));
430
            // Fermer la fen?tre
431
            Close;
432
          finally
433
            ClientDataSetIngredients.EnableControls;
434
          end;
435
        end;
436
    finally
437
      ClientDataSetComposition.Filtered := False;
438
      ClientDataSetComposition.Filter := '';
439
    end;
440
  end;
441
end;
442
443
procedure TFormIngredientDetail.ActionHelpExecute(Sender: TObject);
444
begin
445
  Application.HelpContext(HelpContext);
446
end;
447
448
procedure TFormIngredientDetail.ActionModifyExecute(Sender: TObject);
449
begin
450
  if DataModuleDeclaration.ClientDataSetIngredientsModel.IsNull
451
  then // Cr?ation originale
452
  begin
453
    FormIngredientEditionOriginal := TFormIngredientEditionOriginal.Create(nil);
454
    try
455
      FormIngredientEditionOriginal.ShowModal;
456
    finally
457
      FormIngredientEditionOriginal.Release;
458
    end;
459
  end
460
  else // Copie des tables de r?f?rence
461
  begin
462
    FormIngredientEditionCopy := TFormIngredientEditionCopy.Create(nil);
463
    try
464
      FormIngredientEditionCopy.ShowModal;
465
    finally
466
      FormIngredientEditionCopy.Release;
467
    end;
468
  end;
469
//  with DataModuleDeclaration do
470
//    Hint := ClientDataSetIngredientsDefinition.Value;
471
end;
472
473
procedure TFormIngredientDetail.ActionPrintExecute(Sender: TObject);
474
begin
475
  if RpDev.PrinterSetupDialog
476
  then
477
  begin
478
    RvSystemReport.DoNativeOutput := False;
479
    RvSystemReport.DefaultDest := rdPrinter;
480
    RvSystemReport.RenderObject := nil;
481
    RvSystemReport.OutputFileName := '';
482
    RvProjectReport.Open;
483
    BuildReport;
484
    with DataModuleDeclaration do
485
      if ClientDataSetIngredientsUser.Value
486
      then // User
487
        TableIngredients.Free;
488
    RvProjectReport.Execute;
489
    Application.ProcessMessages;
490
    RvProjectReport.Close;
491
  end;
492
end;
493
494
procedure TFormIngredientDetail.BuildReport;
495
var
496
  i: Integer;
497
  Page: TRavePage;
498
begin
499
  with DataModuleDeclaration do
500
    if ClientDataSetIngredientsUser.Value
501
    then // User
502
      TableIngredients := DBUser.GetTable('SELECT * FROM Ingredients '
503
        + Format('WHERE Id = %d', [ClientDataSetIngredientsId.Value]));
504
  with DataModuleDeclaration do
505
    if ClientDataSetIngredients.Eof
506
    then // Bug : seconde page blanche
507
      if ClientDataSetIngredients.RecordCount > 1
508
      then
509
      begin
510
        ClientDataSetIngredients.Prior;
511
        ClientDataSetIngredients.Next;
512
      end
513
      else
514
        ClientDataSetIngredients.First;
515
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportIngredient.PageIngredient1', nil) as TRavePage;
516
  for i := 0 to Page.ComponentCount - 1 do
517
  begin
518
    if Page.Components[i].ClassNameIs('TRaveText')
519
    then // Traduire
520
    begin
521
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
522
      then
523
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
524
      TranslateComponent(Page.Components[i]);
525
      if (Page.Components[i] as TRaveText).Name = 'TextMS'
526
      then
527
        with FormOptions do
528
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, ComboBoxProximal.Items[Proximal]]);
529
      if (Page.Components[i] as TRaveText).Name = 'TextUnitProximal'
530
      then
531
        with FormOptions do
532
          if Expression = 0
533
          then // sur frais
534
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxProximal.Items[Proximal]])
535
          else // sur mati?re s?che
536
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxProximal.Items[Proximal], _('DM')]);
537
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyC'
538
      then
539
        with FormOptions do
540
          if Expression = 0
541
          then // sur frais
542
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxEnergy.Items[Energy]])
543
          else // sur mati?re s?che
544
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxEnergy.Items[Energy], _('DM')]);
545
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyT'
546
      then
547
        with FormOptions do
548
          if Expression = 0
549
          then // sur frais
550
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxEnergy.Items[Energy]])
551
          else // sur mati?re s?che
552
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxEnergy.Items[Energy], _('DM')]);
553
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyRatio'
554
      then
555
        (Page.Components[i] as TRaveText).Text := '(%)';
556
      if (Page.Components[i] as TRaveText).Name = 'TextEBt_EBc'
557
      then
558
        (Page.Components[i] as TRaveText).Text := ValidateEditEBt_EBc.Text;
559
      if (Page.Components[i] as TRaveText).Name = 'TextdE'
560
      then
561
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
562
      if (Page.Components[i] as TRaveText).Name = 'TextME_DE'
563
      then
564
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
565
      if (Page.Components[i] as TRaveText).Name = 'TextNE_ME'
566
      then
567
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
568
    end;
569
    if Page.Components[i].ClassNameIs('TRaveDataMemo') and (Screen.Fonts.IndexOf('Arial Unicode MS') <> -1)
570
    then
571
      (Page.Components[i] as TRaveDataMemo).Font.Name := 'Arial Unicode MS';
572
    if Page.Components[i].ClassNameIs('TRaveDataText')
573
    then
574
    begin
575
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
576
      then
577
        (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
578
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextMM'
579
      then
580
        with DataModuleDeclaration do
581
          if ClientDataSetIngredientsUser.Value
582
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
583
          then // Valeur h?rit?e du mod?le
584
          begin
585
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
586
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
587
          end;
588
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextMAT'
589
      then
590
        with DataModuleDeclaration do
591
          if ClientDataSetIngredientsUser.Value
592
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
593
          then // Valeur h?rit?e du mod?le
594
          begin
595
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
596
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
597
          end;
598
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextMG'
599
      then
600
        with DataModuleDeclaration do
601
          if ClientDataSetIngredientsUser.Value
602
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
603
          then // Valeur h?rit?e du mod?le
604
          begin
605
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
606
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
607
          end;
608
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextCB'
609
      then
610
        with DataModuleDeclaration do
611
          if ClientDataSetIngredientsUser.Value
612
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
613
          then // Valeur h?rit?e du mod?le
614
          begin
615
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
616
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
617
          end;
618
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextNDF'
619
      then
620
        with DataModuleDeclaration do
621
          if ClientDataSetIngredientsUser.Value
622
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
623
          then // Valeur h?rit?e du mod?le
624
          begin
625
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
626
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
627
          end;
628
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextADF'
629
      then
630
        with DataModuleDeclaration do
631
          if ClientDataSetIngredientsUser.Value
632
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
633
          then // Valeur h?rit?e du mod?le
634
          begin
635
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
636
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
637
          end;
638
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextADL'
639
      then
640
        with DataModuleDeclaration do
641
          if ClientDataSetIngredientsUser.Value
642
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
643
          then // Valeur h?rit?e du mod?le
644
          begin
645
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
646
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
647
          end;
648
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextAmidon'
649
      then
650
        with DataModuleDeclaration do
651
          if ClientDataSetIngredientsUser.Value
652
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
653
          then // Valeur h?rit?e du mod?le
654
          begin
655
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
656
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
657
          end;
658
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextSucres'
659
      then
660
        with DataModuleDeclaration do
661
          if ClientDataSetIngredientsUser.Value
662
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
663
          then // Valeur h?rit?e du mod?le
664
          begin
665
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
666
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
667
          end;
668
    end;
669
  end;
670
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportIngredient.PageIngredient2', nil) as TRavePage;
671
  for i := 0 to Page.ComponentCount - 1 do
672
  begin
673
    if Page.Components[i].ClassNameIs('TRaveText')
674
    then // Traduire
675
    begin
676
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
677
      then
678
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
679
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAATot'
680
      then
681
        with FormOptions do
682
          if Expression = 0
683
          then // sur frais
684
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxAA.Items[AA]])
685
          else // sur mati?re s?che
686
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxAA.Items[AA], _('DM')]);
687
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAADig'
688
      then
689
        with FormOptions do
690
          if Expression = 0
691
          then // sur frais
692
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxAA.Items[AA]])
693
          else // sur mati?re s?che
694
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxAA.Items[AA], _('DM')]);
695
      if (Page.Components[i] as TRaveText).Name = 'TextUnitMinerals'
696
      then
697
        with FormOptions do
698
          if Expression = 0
699
          then // sur frais
700
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxMinerals.Items[Minerals]])
701
          else // sur mati?re s?che
702
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxMinerals.Items[Minerals], _('DM')]);
703 10 avalancogn
      if (Page.Components[i] as TRaveText).Name = 'TextUnitBE'
704 1 avalancogn
      then
705 10 avalancogn
        with FormOptions do
706
          if Expression = 0
707
          then // sur frais
708
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [_('mEq/kg')])
709
          else // sur mati?re s?che
710
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [_('mEq/kg'), _('DM')]);
711
      if (Page.Components[i] as TRaveText).Name = 'TextDigP'
712
      then
713 1 avalancogn
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
714 10 avalancogn
      TranslateComponent(Page.Components[i]);
715
      if (Page.Components[i] as TRaveText).Name = 'TextUnitdN'
716
      then
717
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
718
      if (Page.Components[i] as TRaveText).Name = 'TextUnitLysd_EN'
719
      then
720
        if FormOptions.Energy = 0
721
        then // MJ
722
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/MJ')])
723
        else // kcal
724
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/1000kcal')]);
725 1 avalancogn
    end;
726
    if Page.Components[i].ClassNameIs('TRaveDataText')
727
    then
728
    begin
729
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
730
      then
731
        (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
732
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextCa'
733
      then
734
        with DataModuleDeclaration do
735
          if ClientDataSetIngredientsUser.Value
736
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
737
          then // Valeur h?rit?e du mod?le
738
          begin
739
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
740
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
741
          end;
742
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextP'
743
      then
744
        with DataModuleDeclaration do
745
          if ClientDataSetIngredientsUser.Value
746
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
747
          then // Valeur h?rit?e du mod?le
748
          begin
749
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
750
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
751
          end;
752 3 avalancogn
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextNa'
753
      then
754
        with DataModuleDeclaration do
755
          if ClientDataSetIngredientsUser.Value
756
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Na'])
757
          then // Valeur h?rit?e du mod?le
758
          begin
759
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
760
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
761
          end;
762
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextK'
763
      then
764
        with DataModuleDeclaration do
765
          if ClientDataSetIngredientsUser.Value
766
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['K'])
767
          then // Valeur h?rit?e du mod?le
768
          begin
769
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
770
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
771
          end;
772
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextCl'
773
      then
774
        with DataModuleDeclaration do
775
          if ClientDataSetIngredientsUser.Value
776
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cl'])
777
          then // Valeur h?rit?e du mod?le
778
          begin
779
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
780
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
781
          end;
782 1 avalancogn
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextdP'
783
      then
784
        with DataModuleDeclaration do
785
          if ClientDataSetIngredientsUser.Value
786
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
787
          then // Valeur h?rit?e du mod?le
788
          begin
789
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
790
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
791
          end;
792
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextdPphy'
793
      then
794
        with DataModuleDeclaration do
795
          if ClientDataSetIngredientsUser.Value
796
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
797
          then // Valeur h?rit?e du mod?le
798
          begin
799
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
800
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
801
          end;
802
    end;
803
  end;
804
end;
805
806
procedure TFormIngredientDetail.EditEmpty(Edit: TJvValidateEdit);
807
begin
808
  Edit.DisplayFormat := dfNone;
809
  Edit.Value := '';
810
end;
811
812
procedure TFormIngredientDetail.EditShadow(Edit: TDBEdit);
813
begin
814
  Edit.Font.Style := Edit.Font.Style + [fsItalic];
815
  Edit.Font.Color := cl3DDkShadow;
816
end;
817
818
procedure TFormIngredientDetail.FormCreate(Sender: TObject);
819
var
820
  ProximalUnit, EnergyUnit, AAUnit, MineralsUnit: String;
821
begin
822
  if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
823
  then
824
    Font.Name := 'Arial Unicode MS';
825
//  PanelButtons.Font.Size := PanelButtons.Font.Size + 2;
826
  PanelButtons.Font.Style := [fsBold];
827
  LabelName.Font.Style := [fsBold];
828
  DBEditName.Font.Style := [fsBold];
829
  TranslateComponent(Self);
830
  with FormOptions do
831 2 avalancogn
    LabelMS.Caption := Format('%s (%s)', [LabelMS.Caption, ComboBoxProximal.Items[Proximal]]);
832
  with FormOptions do
833 1 avalancogn
    if Expression = 0
834
    then // sur frais
835
    begin
836
      ProximalUnit := ComboBoxProximal.Items[Proximal];
837
      EnergyUnit := ComboBoxEnergy.Items[Energy];
838
      AAUnit := ComboBoxAA.Items[AA];
839
      MineralsUnit := ComboBoxMinerals.Items[Minerals];
840
    end
841
    else // sur mati?re s?che
842
    begin
843
      ProximalUnit := Format('%s %s', [ComboBoxProximal.Items[Proximal], _('DM')]);
844
      EnergyUnit := Format('%s %s', [ComboBoxEnergy.Items[Energy], _('DM')]);
845
      AAUnit := Format('%s %s', [ComboBoxAA.Items[AA], _('DM')]);
846
      MineralsUnit := Format('%s %s', [ComboBoxMinerals.Items[Minerals], _('DM')]);
847
    end;
848
  GroupBoxProximal.Caption := Format('%s (%s)', [GroupBoxProximal.Caption, ProximalUnit]);
849 3 avalancogn
  GroupBoxMinerals.Caption := Format('%s (%s)', [GroupBoxMinerals.Caption, MineralsUnit]);
850
  if FormOptions.Expression = 0
851
  then // sur frais
852 5 avalancogn
    LabelBEUnit.Caption := Format('(%s)', [_('mEq/kg')])
853 3 avalancogn
  else // sur mati?re s?che
854 5 avalancogn
    LabelBEUnit.Caption := Format('(%s %s)', [_('mEq/kg'), _('DM')]);
855 3 avalancogn
  LabelDigP.Caption := Format('%s (%%)', [LabelDigP.Caption]);
856 1 avalancogn
  GroupBoxEnergy.Caption := Format('%s (%s)', [GroupBoxEnergy.Caption, EnergyUnit]);
857
  LabelRatio.Caption := Format('%s (%%)', [LabelRatio.Caption]);
858
  GroupBoxEnergyUtilization.Caption := Format('%s (%%)', [GroupBoxEnergyUtilization.Caption]);
859 2 avalancogn
//  GroupBoxAzote.Caption := Format('%s (%%)', [GroupBoxAzote.Caption]);
860
  LabeldN.Caption := Format('%s (%%)', [LabeldN.Caption]);
861 1 avalancogn
  if FormOptions.Energy = 0
862
  then // MJ
863
    LabelLysd_EN.Caption := Format('%s (%s)', [LabelLysd_EN.Caption, _('g/MJ')])
864
  else // kcal
865
    LabelLysd_EN.Caption := Format('%s (%s)', [LabelLysd_EN.Caption, _('g/1000kcal')]);
866
  GroupBoxAA.Caption := Format('%s (%s)', [GroupBoxAA.Caption, AAUnit]);
867
  LabeldAA.Caption := Format('%s (%%)', [LabeldAA.Caption]);
868
end;
869
870
procedure TFormIngredientDetail.FormShow(Sender: TObject);
871
begin
872
  with DataModuleDeclaration do
873
  begin
874 9 avalancogn
    if ClientDataSetIngredientsEB.Value = 0
875 1 avalancogn
    then
876
      EditEmpty(ValidateEditEBt_EBc)
877
    else
878
      ValidateEditEBt_EBc.Value := 100;
879
    if ClientDataSetIngredientsUser.Value
880
    then // Mati?re premi?re utilisateur
881
    begin
882
      TableIngredients := DBUser.GetTable('SELECT * FROM Ingredients '
883
        + Format('WHERE Id = %d', [ClientDataSetIngredientsId.Value]));
884
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
885
      then // Valeur h?rit?e du mod?le
886
        EditShadow(DBEditMM);
887
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
888
      then // Valeur h?rit?e du mod?le
889
        EditShadow(DBEditMAT);
890
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
891
      then // Valeur h?rit?e du mod?le
892
        EditShadow(DBEditMG);
893
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
894
      then // Valeur h?rit?e du mod?le
895
        EditShadow(DBEditCB);
896
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
897
      then // Valeur h?rit?e du mod?le
898
        EditShadow(DBEditNDF);
899
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
900
      then // Valeur h?rit?e du mod?le
901
        EditShadow(DBEditADF);
902
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
903
      then // Valeur h?rit?e du mod?le
904
        EditShadow(DBEditADL);
905
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
906
      then // Valeur h?rit?e du mod?le
907
        EditShadow(DBEditAmidon);
908
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
909
      then // Valeur h?rit?e du mod?le
910
        EditShadow(DBEditSucres);
911
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
912
      then // Valeur h?rit?e du mod?le
913
        EditShadow(DBEditCa);
914
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
915
      then // Valeur h?rit?e du mod?le
916
        EditShadow(DBEditP);
917 3 avalancogn
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Na'])
918
      then // Valeur h?rit?e du mod?le
919
        EditShadow(DBEditNa);
920
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['K'])
921
      then // Valeur h?rit?e du mod?le
922
        EditShadow(DBEditK);
923
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cl'])
924
      then // Valeur h?rit?e du mod?le
925
        EditShadow(DBEditCl);
926 1 avalancogn
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
927
      then // Valeur h?rit?e du mod?le
928
        EditShadow(DBEditdPphy);
929
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
930
      then // Valeur h?rit?e du mod?le
931
        EditShadow(DBEditdP);
932
      TableIngredients.Free;
933
    end
934
    else // Mati?re premi?re de r?f?rence
935
    begin
936
      JvImgBtnModify.Enabled := False;
937
      JvImgBtnDelete.Enabled := False;
938
    end;
939
  end;
940
end;
941
942
end.