Statistiques
| Révision:

root / UnitIngredientDetail.pas @ 5

Historique | Voir | Annoter | Télécharger (37,076 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
      TranslateComponent(Page.Components[i]);
680
      if (Page.Components[i] as TRaveText).Name = 'TextdN'
681
      then
682
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
683
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAATot'
684
      then
685
        with FormOptions do
686
          if Expression = 0
687
          then // sur frais
688
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxAA.Items[AA]])
689
          else // sur mati?re s?che
690
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxAA.Items[AA], _('DM')]);
691
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAADig'
692
      then
693
        with FormOptions do
694
          if Expression = 0
695
          then // sur frais
696
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxAA.Items[AA]])
697
          else // sur mati?re s?che
698
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxAA.Items[AA], _('DM')]);
699
      if (Page.Components[i] as TRaveText).Name = 'TextUnitLysd_EN'
700
      then
701
        if FormOptions.Energy = 0
702
        then // MJ
703
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/MJ')])
704
        else // kcal
705
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/1000kcal')]);
706
      if (Page.Components[i] as TRaveText).Name = 'TextUnitMinerals'
707
      then
708
        with FormOptions do
709
          if Expression = 0
710
          then // sur frais
711
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxMinerals.Items[Minerals]])
712
          else // sur mati?re s?che
713
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxMinerals.Items[Minerals], _('DM')]);
714
      if (Page.Components[i] as TRaveText).Name = 'TextdP'
715
      then
716
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
717
    end;
718
    if Page.Components[i].ClassNameIs('TRaveDataText')
719
    then
720
    begin
721
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
722
      then
723
        (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
724
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextCa'
725
      then
726
        with DataModuleDeclaration do
727
          if ClientDataSetIngredientsUser.Value
728
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
729
          then // Valeur h?rit?e du mod?le
730
          begin
731
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
732
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
733
          end;
734
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextP'
735
      then
736
        with DataModuleDeclaration do
737
          if ClientDataSetIngredientsUser.Value
738
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
739
          then // Valeur h?rit?e du mod?le
740
          begin
741
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
742
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
743
          end;
744 3 avalancogn
(*
745
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextNa'
746
      then
747
        with DataModuleDeclaration do
748
          if ClientDataSetIngredientsUser.Value
749
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Na'])
750
          then // Valeur h?rit?e du mod?le
751
          begin
752
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
753
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
754
          end;
755
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextK'
756
      then
757
        with DataModuleDeclaration do
758
          if ClientDataSetIngredientsUser.Value
759
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['K'])
760
          then // Valeur h?rit?e du mod?le
761
          begin
762
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
763
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
764
          end;
765
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextCl'
766
      then
767
        with DataModuleDeclaration do
768
          if ClientDataSetIngredientsUser.Value
769
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cl'])
770
          then // Valeur h?rit?e du mod?le
771
          begin
772
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
773
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
774
          end;
775
*)
776 1 avalancogn
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextdP'
777
      then
778
        with DataModuleDeclaration do
779
          if ClientDataSetIngredientsUser.Value
780
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
781
          then // Valeur h?rit?e du mod?le
782
          begin
783
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
784
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
785
          end;
786
      if (Page.Components[i] as TRaveDataText).Name = 'DataTextdPphy'
787
      then
788
        with DataModuleDeclaration do
789
          if ClientDataSetIngredientsUser.Value
790
          and TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
791
          then // Valeur h?rit?e du mod?le
792
          begin
793
            (Page.Components[i] as TRaveDataText).Font.Style := (Page.Components[i] as TRaveDataText).Font.Style + [fsItalic];
794
            (Page.Components[i] as TRaveDataText).Font.Color := clGray;
795
          end;
796
    end;
797
  end;
798
end;
799
800
procedure TFormIngredientDetail.EditEmpty(Edit: TJvValidateEdit);
801
begin
802
  Edit.DisplayFormat := dfNone;
803
  Edit.Value := '';
804
end;
805
806
procedure TFormIngredientDetail.EditShadow(Edit: TDBEdit);
807
begin
808
  Edit.Font.Style := Edit.Font.Style + [fsItalic];
809
  Edit.Font.Color := cl3DDkShadow;
810
end;
811
812
procedure TFormIngredientDetail.FormCreate(Sender: TObject);
813
var
814
  ProximalUnit, EnergyUnit, AAUnit, MineralsUnit: String;
815
begin
816
  if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
817
  then
818
    Font.Name := 'Arial Unicode MS';
819
//  PanelButtons.Font.Size := PanelButtons.Font.Size + 2;
820
  PanelButtons.Font.Style := [fsBold];
821
  LabelName.Font.Style := [fsBold];
822
  DBEditName.Font.Style := [fsBold];
823
  TranslateComponent(Self);
824
  with FormOptions do
825 2 avalancogn
    LabelMS.Caption := Format('%s (%s)', [LabelMS.Caption, ComboBoxProximal.Items[Proximal]]);
826
  with FormOptions do
827 1 avalancogn
    if Expression = 0
828
    then // sur frais
829
    begin
830
      ProximalUnit := ComboBoxProximal.Items[Proximal];
831
      EnergyUnit := ComboBoxEnergy.Items[Energy];
832
      AAUnit := ComboBoxAA.Items[AA];
833
      MineralsUnit := ComboBoxMinerals.Items[Minerals];
834
    end
835
    else // sur mati?re s?che
836
    begin
837
      ProximalUnit := Format('%s %s', [ComboBoxProximal.Items[Proximal], _('DM')]);
838
      EnergyUnit := Format('%s %s', [ComboBoxEnergy.Items[Energy], _('DM')]);
839
      AAUnit := Format('%s %s', [ComboBoxAA.Items[AA], _('DM')]);
840
      MineralsUnit := Format('%s %s', [ComboBoxMinerals.Items[Minerals], _('DM')]);
841
    end;
842
  GroupBoxProximal.Caption := Format('%s (%s)', [GroupBoxProximal.Caption, ProximalUnit]);
843 3 avalancogn
  GroupBoxMinerals.Caption := Format('%s (%s)', [GroupBoxMinerals.Caption, MineralsUnit]);
844
  if FormOptions.Expression = 0
845
  then // sur frais
846 5 avalancogn
    LabelBEUnit.Caption := Format('(%s)', [_('mEq/kg')])
847 3 avalancogn
  else // sur mati?re s?che
848 5 avalancogn
    LabelBEUnit.Caption := Format('(%s %s)', [_('mEq/kg'), _('DM')]);
849 3 avalancogn
  LabelDigP.Caption := Format('%s (%%)', [LabelDigP.Caption]);
850 1 avalancogn
  GroupBoxEnergy.Caption := Format('%s (%s)', [GroupBoxEnergy.Caption, EnergyUnit]);
851
  LabelRatio.Caption := Format('%s (%%)', [LabelRatio.Caption]);
852
  GroupBoxEnergyUtilization.Caption := Format('%s (%%)', [GroupBoxEnergyUtilization.Caption]);
853 2 avalancogn
//  GroupBoxAzote.Caption := Format('%s (%%)', [GroupBoxAzote.Caption]);
854
  LabeldN.Caption := Format('%s (%%)', [LabeldN.Caption]);
855 1 avalancogn
  if FormOptions.Energy = 0
856
  then // MJ
857
    LabelLysd_EN.Caption := Format('%s (%s)', [LabelLysd_EN.Caption, _('g/MJ')])
858
  else // kcal
859
    LabelLysd_EN.Caption := Format('%s (%s)', [LabelLysd_EN.Caption, _('g/1000kcal')]);
860
  GroupBoxAA.Caption := Format('%s (%s)', [GroupBoxAA.Caption, AAUnit]);
861
  LabeldAA.Caption := Format('%s (%%)', [LabeldAA.Caption]);
862
end;
863
864
procedure TFormIngredientDetail.FormShow(Sender: TObject);
865
begin
866
  with DataModuleDeclaration do
867
  begin
868
    if ClientDataSetIngredientsEB.IsNull
869
    then
870
      EditEmpty(ValidateEditEBt_EBc)
871
    else
872
      ValidateEditEBt_EBc.Value := 100;
873
    if ClientDataSetIngredientsUser.Value
874
    then // Mati?re premi?re utilisateur
875
    begin
876
      TableIngredients := DBUser.GetTable('SELECT * FROM Ingredients '
877
        + Format('WHERE Id = %d', [ClientDataSetIngredientsId.Value]));
878
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
879
      then // Valeur h?rit?e du mod?le
880
        EditShadow(DBEditMM);
881
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
882
      then // Valeur h?rit?e du mod?le
883
        EditShadow(DBEditMAT);
884
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
885
      then // Valeur h?rit?e du mod?le
886
        EditShadow(DBEditMG);
887
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
888
      then // Valeur h?rit?e du mod?le
889
        EditShadow(DBEditCB);
890
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
891
      then // Valeur h?rit?e du mod?le
892
        EditShadow(DBEditNDF);
893
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
894
      then // Valeur h?rit?e du mod?le
895
        EditShadow(DBEditADF);
896
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
897
      then // Valeur h?rit?e du mod?le
898
        EditShadow(DBEditADL);
899
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
900
      then // Valeur h?rit?e du mod?le
901
        EditShadow(DBEditAmidon);
902
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
903
      then // Valeur h?rit?e du mod?le
904
        EditShadow(DBEditSucres);
905
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
906
      then // Valeur h?rit?e du mod?le
907
        EditShadow(DBEditCa);
908
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
909
      then // Valeur h?rit?e du mod?le
910
        EditShadow(DBEditP);
911 3 avalancogn
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Na'])
912
      then // Valeur h?rit?e du mod?le
913
        EditShadow(DBEditNa);
914
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['K'])
915
      then // Valeur h?rit?e du mod?le
916
        EditShadow(DBEditK);
917
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cl'])
918
      then // Valeur h?rit?e du mod?le
919
        EditShadow(DBEditCl);
920 1 avalancogn
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
921
      then // Valeur h?rit?e du mod?le
922
        EditShadow(DBEditdPphy);
923
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
924
      then // Valeur h?rit?e du mod?le
925
        EditShadow(DBEditdP);
926
      TableIngredients.Free;
927
    end
928
    else // Mati?re premi?re de r?f?rence
929
    begin
930
      JvImgBtnModify.Enabled := False;
931
      JvImgBtnDelete.Enabled := False;
932
    end;
933
  end;
934
end;
935
936
end.