Statistiques
| Révision:

root / UnitFeedCharts.pas @ 1

Historique | Voir | Annoter | Télécharger (111,583 ko)

1 1 avalancogn
unit UnitFeedCharts;
2
3
interface
4
5
uses
6
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7
  gnugettext, StdCtrls, ExtCtrls, TeeProcs, TeEngine, Chart, Series, Buttons,
8
  Math, ComCtrls, JvExStdCtrls, JvButton, JvCtrls, ActnList, ImgList;
9
10
type
11
  TFormFeedCharts = class(TForm)
12
    Chart0: TChart;
13
    SeriesPie: TPieSeries;
14
    SpeedButton2D3D0: TSpeedButton;
15
    SpeedButtonPrint0: TSpeedButton;
16
    GroupBoxChart0: TGroupBox;
17
    PageControlFeedCharts: TPageControl;
18
    TabSheetSingleChart: TTabSheet;
19
    TabSheetChartsComparison: TTabSheet;
20
    GroupBoxChart1: TGroupBox;
21
    GroupBoxChart2: TGroupBox;
22
    GroupBoxChart3: TGroupBox;
23
    GroupBoxChart4: TGroupBox;
24
    Chart1: TChart;
25
    SpeedButton2D3D1: TSpeedButton;
26
    SpeedButtonPrint1: TSpeedButton;
27
    PanelChart1: TPanel;
28
    PanelChart2: TPanel;
29
    PanelChart3: TPanel;
30
    PanelChart4: TPanel;
31
    Chart2: TChart;
32
    SpeedButton2D3D2: TSpeedButton;
33
    SpeedButtonPrint2: TSpeedButton;
34
    Chart3: TChart;
35
    SpeedButton2D3D3: TSpeedButton;
36
    SpeedButtonPrint3: TSpeedButton;
37
    Chart4: TChart;
38
    SpeedButton2D3D4: TSpeedButton;
39
    SpeedButtonPrint4: TSpeedButton;
40
    PanelButtons: TPanel;
41
    ComboBoxAA0: TComboBox;
42
    ComboBoxEnergy0: TComboBox;
43
    ComboBoxMinerals0: TComboBox;
44
    ComboBoxProximal0: TComboBox;
45
    ComboBoxType0: TComboBox;
46
    ComboBoxAA1: TComboBox;
47
    ComboBoxEnergy1: TComboBox;
48
    ComboBoxMinerals1: TComboBox;
49
    ComboBoxProximal1: TComboBox;
50
    ComboBoxType1: TComboBox;
51
    ComboBoxAA2: TComboBox;
52
    ComboBoxEnergy2: TComboBox;
53
    ComboBoxMinerals2: TComboBox;
54
    ComboBoxProximal2: TComboBox;
55
    ComboBoxType2: TComboBox;
56
    ComboBoxAA3: TComboBox;
57
    ComboBoxEnergy3: TComboBox;
58
    ComboBoxMinerals3: TComboBox;
59
    ComboBoxProximal3: TComboBox;
60
    ComboBoxType3: TComboBox;
61
    ComboBoxAA4: TComboBox;
62
    ComboBoxEnergy4: TComboBox;
63
    ComboBoxMinerals4: TComboBox;
64
    ComboBoxProximal4: TComboBox;
65
    ComboBoxType4: TComboBox;
66
    ImageListIcons: TImageList;
67
    ActionListButtons: TActionList;
68
    ActionHelp: TAction;
69
    ActionClose: TAction;
70
    JvImgBtnClose: TJvImgBtn;
71
    JvImgBtnHelp: TJvImgBtn;
72
    procedure FormCreate(Sender: TObject);
73
    procedure ComboBoxType0Change(Sender: TObject);
74
    procedure FormShow(Sender: TObject);
75
    procedure ComboBoxOption0Change(Sender: TObject);
76
    procedure SpeedButton2D3D0Click(Sender: TObject);
77
    procedure SpeedButtonPrint0Click(Sender: TObject);
78
    procedure FormDestroy(Sender: TObject);
79
    procedure FormResize(Sender: TObject);
80
    procedure ComboBoxType1Change(Sender: TObject);
81
    procedure ComboBoxType2Change(Sender: TObject);
82
    procedure ComboBoxType3Change(Sender: TObject);
83
    procedure ComboBoxType4Change(Sender: TObject);
84
    procedure ComboBoxOption1Change(Sender: TObject);
85
    procedure ComboBoxOption2Change(Sender: TObject);
86
    procedure ComboBoxOption3Change(Sender: TObject);
87
    procedure ComboBoxOption4Change(Sender: TObject);
88
    procedure SpeedButton2D3D1Click(Sender: TObject);
89
    procedure SpeedButton2D3D2Click(Sender: TObject);
90
    procedure SpeedButton2D3D3Click(Sender: TObject);
91
    procedure SpeedButton2D3D4Click(Sender: TObject);
92
    procedure SpeedButtonPrint1Click(Sender: TObject);
93
    procedure SpeedButtonPrint2Click(Sender: TObject);
94
    procedure SpeedButtonPrint3Click(Sender: TObject);
95
    procedure SpeedButtonPrint4Click(Sender: TObject);
96
    procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
97
    procedure ActionHelpExecute(Sender: TObject);
98
    procedure ActionCloseExecute(Sender: TObject);
99
  private
100
    { D?clarations priv?es }
101
  public
102
    { D?clarations publiques }
103
  end;
104
105
var
106
  FormFeedCharts: TFormFeedCharts;
107
108
implementation
109
110
uses
111
  UnitDeclaration, UnitOptions, UnitChartHReport;
112
113
{$R *.dfm}
114
115
procedure TFormFeedCharts.ActionCloseExecute(Sender: TObject);
116
begin
117
  ModalResult := mrClose;
118
end;
119
120
procedure TFormFeedCharts.ActionHelpExecute(Sender: TObject);
121
begin
122
  Application.HelpContext(HelpContext);
123
end;
124
125
procedure TFormFeedCharts.ComboBoxOption0Change(Sender: TObject);
126
var
127
  IngredientName: String;
128
  Ratio, Total, Value: Double;
129
begin
130
  SeriesPie.Clear;
131
  Chart0.SubTitle.Clear;
132
  with DataModuleDeclaration do
133
  begin
134
    Chart0.Title.Caption := ClientDataSetFeedsName.Value;
135
    Chart0.SubTitle.Text.Add(ComboBoxType0.Text);
136
    case ComboBoxType0.ItemIndex of
137
      0: // Analyse proximale
138
        Chart0.SubTitle.Text.Add(ComboBoxProximal0.Text);
139
      1: // Valeurs ?nerg?tiques
140
        Chart0.SubTitle.Text.Add(ComboBoxEnergy0.Text);
141
      2, 3: // Acides amin?s
142
        Chart0.SubTitle.Text.Add(ComboBoxAA0.Text);
143
      4: // Min?raux
144
        Chart0.SubTitle.Text.Add(ComboBoxMinerals0.Text);
145
    end;
146
    ClientDataSetComposition.First;
147
    Total := 0;
148
    while not ClientDataSetComposition.Eof do
149
    begin
150
      if ClientDataSetCompositionUser.Value
151
      then
152
        ClientDataSetIngredients.Filter := Format('Id = %d and User', [ClientDataSetCompositionIngredient.Value])
153
      else
154
        ClientDataSetIngredients.Filter := Format('Id = %d and not User', [ClientDataSetCompositionIngredient.Value]);
155
      ClientDataSetIngredients.Filtered := True;
156
      IngredientName := StrTrunc(ClientDataSetIngredientsName.Value, 25);
157
      Ratio := InputIncorporation(ClientDataSetCompositionLevel.Value, FormOptions.Incorporation);
158
      if (FormOptions.Expression = 0)
159
      and ((ComboBoxType0.ItemIndex <> 0) or (ComboBoxProximal0.ItemIndex > 1))
160
      then // Conversion frais -> sec (mati?re s?che de la mati?re premi?re) - except? pour Composition et MS
161
        Ratio := Ratio / InputProximal(ClientDataSetIngredientsMS.Value, 1, 1, FormOptions.Proximal);
162
      RapMS := InputProximal(ClientDataSetCompositionMS.Value, 1, 1, FormOptions.Proximal);
163
      if ((ComboBoxType0.ItemIndex <> 0) or (ComboBoxProximal0.ItemIndex > 1))
164
      then // Conversion sec -> frais (mati?re s?che de la composition) - except? pour Composition et MS
165
        Ratio := Ratio * RapMS;
166
      case ComboBoxType0.ItemIndex of
167
        0: // Analyse proximale
168
          case ComboBoxProximal0.ItemIndex of
169
            0: // Composition
170
              Value := OutputProximal(Ratio, 1, 1, FormOptions.Proximal);
171
            1: // MS
172
              Value := ClientDataSetCompositionMS.Value * Ratio;
173
            2: // MM
174
              Value := ClientDataSetIngredientsMM.Value * Ratio;
175
            3: // MAT
176
              Value := ClientDataSetIngredientsMAT.Value * Ratio;
177
            4: // MG
178
              Value := ClientDataSetIngredientsMG.Value * Ratio;
179
            5: // CB
180
              Value := ClientDataSetIngredientsCB.Value * Ratio;
181
            6: // NDF
182
              Value := ClientDataSetIngredientsNDF.Value * Ratio;
183
            7: // ADF
184
              Value := ClientDataSetIngredientsADF.Value * Ratio;
185
            8: // ADL
186
              Value := ClientDataSetIngredientsADL.Value * Ratio;
187
            9: // Amidon
188
              Value := ClientDataSetIngredientsAmidon.Value * Ratio;
189
            10: // Sucres
190
              Value := ClientDataSetIngredientsSucres.Value * Ratio;
191
            else
192
              Value := 0;
193
          end;
194
        1: // Valeurs ?nerg?tiques
195
          case ComboBoxEnergy0.ItemIndex of
196
            0: // Energie brute
197
              Value := ClientDataSetIngredientsEB.Value * Ratio;
198
            1: // Energie digestible (porc croissance)
199
              Value := ClientDataSetIngredientsEDc.Value * Ratio;
200
            2: // Energie digestible (porc adulte)
201
              Value := ClientDataSetIngredientsEDt.Value * Ratio;
202
            3: // Energie m?tabolisable (porc croissance)
203
              Value := ClientDataSetIngredientsEMc.Value * Ratio;
204
            4: // Energie m?tabolisable (porc adulte)
205
              Value := ClientDataSetIngredientsEMt.Value * Ratio;
206
            5: // Energie nette (porc croissance)
207
              Value := ClientDataSetIngredientsENc.Value * Ratio;
208
            6: // Energie nette (porc adulte)
209
              Value := ClientDataSetIngredientsENt.Value * Ratio;
210
            else
211
              Value := 0;
212
          end;
213
        2: // Acides amin?s totaux
214
          case ComboBoxAA0.ItemIndex of
215
            0: // Lysine
216
              Value := ClientDataSetIngredientsLys.Value * Ratio;
217
            1: // Thr?onine
218
              Value := ClientDataSetIngredientsThr.Value * Ratio;
219
            2: // M?thionine
220
              Value := ClientDataSetIngredientsMet.Value * Ratio;
221
            3: // Cyst?ine
222
              Value := ClientDataSetIngredientsCys.Value * Ratio;
223
            4: // M?thionine + Cyst?ine
224
              Value := ClientDataSetIngredientsMetCys.Value * Ratio;
225
            5: // Tryptophane
226
              Value := ClientDataSetIngredientsTrp.Value * Ratio;
227
            6: // Isoleucine
228
              Value := ClientDataSetIngredientsIle.Value * Ratio;
229
            7: // Valine
230
              Value := ClientDataSetIngredientsVal.Value * Ratio;
231
            8: // Leucine
232
              Value := ClientDataSetIngredientsLeu.Value * Ratio;
233
            9: // Ph?nylalanine
234
              Value := ClientDataSetIngredientsPhe.Value * Ratio;
235
            10: // Tyrosine
236
              Value := ClientDataSetIngredientsTyr.Value * Ratio;
237
            11: // Ph?nylalanine + Tyrosine
238
              Value := ClientDataSetIngredientsPheTyr.Value * Ratio;
239
            12: // Histidine
240
              Value := ClientDataSetIngredientsHis.Value * Ratio;
241
            13: // Arginine
242
              Value := ClientDataSetIngredientsArg.Value * Ratio;
243
            14: // Alanine
244
              Value := ClientDataSetIngredientsAla.Value * Ratio;
245
            15: // Aspartate
246
              Value := ClientDataSetIngredientsAsp.Value * Ratio;
247
            16: // Glutamate
248
              Value := ClientDataSetIngredientsGlu.Value * Ratio;
249
            17: // Glycine
250
              Value := ClientDataSetIngredientsGly.Value * Ratio;
251
            18: // S?rine
252
              Value := ClientDataSetIngredientsSer.Value * Ratio;
253
            19: // Proline
254
              Value := ClientDataSetIngredientsPro.Value * Ratio;
255
            else
256
              Value := 0;
257
          end;
258
        3: // Acides amin?s digestibles
259
          case ComboBoxAA0.ItemIndex of
260
            0: // Lysine
261
              Value := ClientDataSetIngredientsLysd.Value * Ratio;
262
            1: // Thr?onine
263
              Value := ClientDataSetIngredientsThrd.Value * Ratio;
264
            2: // M?thionine
265
              Value := ClientDataSetIngredientsMetd.Value * Ratio;
266
            3: // Cyst?ine
267
              Value := ClientDataSetIngredientsCysd.Value * Ratio;
268
            4: // M?thionine + Cyst?ine
269
              Value := ClientDataSetIngredientsMetCysd.Value * Ratio;
270
            5: // Tryptophane
271
              Value := ClientDataSetIngredientsTrpd.Value * Ratio;
272
            6: // Isoleucine
273
              Value := ClientDataSetIngredientsIled.Value * Ratio;
274
            7: // Valine
275
              Value := ClientDataSetIngredientsVald.Value * Ratio;
276
            8: // Leucine
277
              Value := ClientDataSetIngredientsLeud.Value * Ratio;
278
            9: // Ph?nylalanine
279
              Value := ClientDataSetIngredientsPhed.Value * Ratio;
280
            10: // Tyrosine
281
              Value := ClientDataSetIngredientsTyrd.Value * Ratio;
282
            11: // Ph?nylalanine + Tyrosine
283
              Value := ClientDataSetIngredientsPheTyrd.Value * Ratio;
284
            12: // Histidine
285
              Value := ClientDataSetIngredientsHisd.Value * Ratio;
286
            13: // Arginine
287
              Value := ClientDataSetIngredientsArgd.Value * Ratio;
288
            14: // Alanine
289
              Value := ClientDataSetIngredientsAlad.Value * Ratio;
290
            15: // Aspartate
291
              Value := ClientDataSetIngredientsAspd.Value * Ratio;
292
            16: // Glutamate
293
              Value := ClientDataSetIngredientsGlud.Value * Ratio;
294
            17: // Glycine
295
              Value := ClientDataSetIngredientsGlyd.Value * Ratio;
296
            18: // S?rine
297
              Value := ClientDataSetIngredientsSerd.Value * Ratio;
298
            19: // Proline
299
              Value := ClientDataSetIngredientsProd.Value * Ratio;
300
            else
301
              Value := 0;
302
          end;
303
        4: // Min?raux
304
          case ComboBoxMinerals0.ItemIndex of
305
            0: // Calcium
306
              Value := ClientDataSetIngredientsCa.Value * Ratio;
307
            1: // Phosphore
308
              Value := ClientDataSetIngredientsP.Value * Ratio;
309
            2: // Phosphore digestible
310
              if ClientDataSetFeedsPresentation.Value = 0
311
              then // Farine (dPphy)
312
                Value := ClientDataSetIngredientsdPphy.Value / 100 * ClientDataSetIngredientsP.Value * Ratio
313
              else // Granul?s (dP)
314
                Value := ClientDataSetIngredientsdP.Value / 100 * ClientDataSetIngredientsP.Value * Ratio;
315
            else
316
              Value := 0;
317
          end;
318
        else
319
          Value := 0;
320
      end;
321
      if (FormOptions.Expression = 1)
322
      and ((ComboBoxType0.ItemIndex <> 0) or (ComboBoxProximal0.ItemIndex > 1))
323
      then // Conversion frais -> sec (mati?re s?che du r?gime) - except? pour Composition et MS
324
        Value := Value / InputProximal(ClientDataSetFeedsMS.Value, 1, 1, FormOptions.Proximal);
325
      if Value > 0
326
      then // Prendre en compte la valeur
327
      begin
328
        SeriesPie.AddPie(Value, IngredientName);
329
        Total := Total + Value;
330
      end;
331
      ClientDataSetComposition.Next;
332
    end;
333
    ClientDataSetIngredients.Filtered := False;
334
    ClientDataSetIngredients.Filter := '';
335
    // Cas particuliers
336
    if (ComboBoxType0.ItemIndex = 1)
337
    and ((ComboBoxEnergy0.ItemIndex = 1)
338
      or (ComboBoxEnergy0.ItemIndex = 3)
339
      or (ComboBoxEnergy0.ItemIndex = 5))
340
    and (ClientDataSetFeedsBonusC.Value > 0)
341
    then // Bonus ?nergie (porc croissance)
342
    begin
343
      case ComboBoxEnergy0.ItemIndex of
344
        1: Value := ClientDataSetFeedsEDc.Value - Total;
345
        3: Value := ClientDataSetFeedsEMc.Value - Total;
346
        5: Value := ClientDataSetFeedsENc.Value - Total;
347
        else Value := 0;
348
      end;
349
      SeriesPie.AddPie(Value, _('Energy bonus'));
350
      Total := Total + Value;
351
    end;
352
    if (ComboBoxType0.ItemIndex = 1)
353
    and ((ComboBoxEnergy0.ItemIndex = 2)
354
      or (ComboBoxEnergy0.ItemIndex = 4)
355
      or (ComboBoxEnergy0.ItemIndex = 6))
356
    and (ClientDataSetFeedsBonusT.Value > 0)
357
    then // Bonus ?nergie (porc adulte)
358
    begin
359
      case ComboBoxEnergy0.ItemIndex of
360
        2: Value := ClientDataSetFeedsEDt.Value - Total;
361
        4: Value := ClientDataSetFeedsEMt.Value - Total;
362
        6: Value := ClientDataSetFeedsENt.Value - Total;
363
        else Value := 0;
364
      end;
365
      SeriesPie.AddPie(Value, _('Energy bonus'));
366
      Total := Total + Value;
367
    end;
368
    if (ComboBoxType0.ItemIndex = 0)
369
    and (ComboBoxProximal0.ItemIndex = 0)
370
    and not ClientDataSetFeedsPhytaseId.IsNull
371
    and (ClientDataSetFeedsPhytaseLevel.Value > 0)
372
    then // Phytase (taux d'incorporation)
373
    begin
374
      Ratio := InputIncorporation(ClientDataSetFeedsPhytaseLevel.Value, FormOptions.Incorporation);
375
      Value := OutputProximal(Ratio, 1, 1, FormOptions.Proximal);
376
      SeriesPie.AddPie(Value, _('Phytase'));
377
      Total := Total + Value;
378
    end;
379
    if (ComboBoxType0.ItemIndex = 4)
380
    and (ComboBoxMinerals0.ItemIndex = 2)
381
    and not ClientDataSetFeedsPhytaseId.IsNull
382
    and (ClientDataSetFeedsPd.Value > Total)
383
    then // Phytase (Phosphore digestible)
384
    begin
385
      Value := ClientDataSetFeedsPd.Value - Total;
386
      SeriesPie.AddPie(Value, _('Phytase'));
387
      Total := Total + Value;
388
    end;
389
  end;
390
  // Total
391
  case ComboBoxType0.ItemIndex of
392
    0: // Analyse proximale
393
      if (FormOptions.Expression = 0) or (ComboBoxProximal0.ItemIndex < 2)
394
      then // sur frais
395
        Chart0.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.ProximalDecimals, Total, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal]]))
396
      else // sur mati?re s?che - except? pour Composition et MS
397
        Chart0.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.ProximalDecimals, Total, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]));
398
    1: // Valeurs ?nerg?tiques
399
      if FormOptions.Expression = 0
400
      then // sur frais
401
        Chart0.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.EnergyDecimals, Total, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy]]))
402
      else // sur mati?re s?che
403
        Chart0.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.EnergyDecimals, Total, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]));
404
    2, 3: // Acides amin?s
405
      if FormOptions.Expression = 0
406
      then // sur frais
407
        Chart0.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.AADecimals, Total, FormOptions.ComboBoxAA.Items[FormOptions.AA]]))
408
      else // sur mati?re s?che
409
        Chart0.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.AADecimals, Total, FormOptions.ComboBoxAA.Items[FormOptions.AA], _('DM')]));
410
    4: // Min?raux
411
      if FormOptions.Expression = 0
412
      then // sur frais
413
        Chart0.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.MineralsDecimals, Total, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals]]))
414
      else // sur mati?re s?che
415
        Chart0.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.MineralsDecimals, Total, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], _('DM')]));
416
  end;
417
end;
418
419
procedure TFormFeedCharts.ComboBoxOption1Change(Sender: TObject);
420
var
421
  IngredientName: String;
422
  Cumul, Ratio, Total, Value: Double;
423
  FeedBar: TBarSeries;
424
begin
425
//  while Chart1.SeriesCount > 0 do
426
//    Chart1.Series[0].Free;
427
  Chart1.FreeAllSeries(nil);
428
  Chart1.SubTitle.Clear;
429
  with DataModuleDeclaration do
430
  begin
431
    Chart1.AxisVisible := True;
432
    Chart1.SubTitle.Text.Add(ComboBoxType1.Text);
433
    case ComboBoxType1.ItemIndex of
434
      0: // Analyse proximale
435
        Chart1.SubTitle.Text.Add(ComboBoxProximal1.Text);
436
      1: // Valeurs ?nerg?tiques
437
        Chart1.SubTitle.Text.Add(ComboBoxEnergy1.Text);
438
      2, 3: // Acides amin?s
439
        Chart1.SubTitle.Text.Add(ComboBoxAA1.Text);
440
      4: // Min?raux
441
        Chart1.SubTitle.Text.Add(ComboBoxMinerals1.Text);
442
    end;
443
    case ComboBoxType1.ItemIndex of
444
      0: // Analyse proximale
445
        case ComboBoxProximal1.ItemIndex of
446
          0: // Composition
447
            Cumul := OutputIncorporation(1, FormOptions.Incorporation);
448
          1: // MS
449
            Cumul := ClientDataSetFeedsMS.Value;
450
          2: // MM
451
            Cumul := ClientDataSetFeedsMM.Value;
452
          3: // MAT
453
            Cumul := ClientDataSetFeedsMAT.Value;
454
          4: // MG
455
            Cumul := ClientDataSetFeedsMG.Value;
456
          5: // CB
457
            Cumul := ClientDataSetFeedsCB.Value;
458
          6: // NDF
459
            Cumul := ClientDataSetFeedsNDF.Value;
460
          7: // ADF
461
            Cumul := ClientDataSetFeedsADF.Value;
462
          8: // ADL
463
            Cumul := ClientDataSetFeedsADL.Value;
464
          9: // Amidon
465
            Cumul := ClientDataSetFeedsAmidon.Value;
466
          10: // Sucres
467
            Cumul := ClientDataSetFeedsSucres.Value;
468
          else
469
            Cumul := 0;
470
        end;
471
      1: // Valeurs ?nerg?tiques
472
        case ComboBoxEnergy1.ItemIndex of
473
          0: // Energie brute
474
            Cumul := ClientDataSetFeedsEB.Value;
475
          1: // Energie digestible (porc croissance)
476
            Cumul := ClientDataSetFeedsEDc.Value;
477
          2: // Energie digestible (porc adulte)
478
            Cumul := ClientDataSetFeedsEDt.Value;
479
          3: // Energie m?tabolisable (porc croissance)
480
            Cumul := ClientDataSetFeedsEMc.Value;
481
          4: // Energie m?tabolisable (porc adulte)
482
            Cumul := ClientDataSetFeedsEMt.Value;
483
          5: // Energie nette (porc croissance)
484
            Cumul := ClientDataSetFeedsENc.Value;
485
          6: // Energie nette (porc adulte)
486
            Cumul := ClientDataSetFeedsENt.Value;
487
          else
488
            Cumul := 0;
489
        end;
490
      2: // Acides amin?s totaux
491
        case ComboBoxAA1.ItemIndex of
492
          0: // Lysine
493
            Cumul := ClientDataSetFeedsLys.Value;
494
          1: // Thr?onine
495
            Cumul := ClientDataSetFeedsThr.Value;
496
          2: // M?thionine
497
            Cumul := ClientDataSetFeedsMet.Value;
498
          3: // Cyst?ine
499
            Cumul := ClientDataSetFeedsCys.Value;
500
          4: // M?thionine + Cyst?ine
501
            Cumul := ClientDataSetFeedsMetCys.Value;
502
          5: // Tryptophane
503
            Cumul := ClientDataSetFeedsTrp.Value;
504
          6: // Isoleucine
505
            Cumul := ClientDataSetFeedsIle.Value;
506
          7: // Valine
507
            Cumul := ClientDataSetFeedsVal.Value;
508
          8: // Leucine
509
            Cumul := ClientDataSetFeedsLeu.Value;
510
          9: // Ph?nylalanine
511
            Cumul := ClientDataSetFeedsPhe.Value;
512
          10: // Tyrosine
513
            Cumul := ClientDataSetFeedsTyr.Value;
514
          11: // Ph?nylalanine + Tyrosine
515
            Cumul := ClientDataSetFeedsPheTyr.Value;
516
          12: // Histidine
517
            Cumul := ClientDataSetFeedsHis.Value;
518
          13: // Arginine
519
            Cumul := ClientDataSetFeedsArg.Value;
520
          14: // Alanine
521
            Cumul := ClientDataSetFeedsAla.Value;
522
          15: // Aspartate
523
            Cumul := ClientDataSetFeedsAsp.Value;
524
          16: // Glutamate
525
            Cumul := ClientDataSetFeedsGlu.Value;
526
          17: // Glycine
527
            Cumul := ClientDataSetFeedsGly.Value;
528
          18: // S?rine
529
            Cumul := ClientDataSetFeedsSer.Value;
530
          19: // Proline
531
            Cumul := ClientDataSetFeedsPro.Value;
532
          else
533
            Cumul := 0;
534
        end;
535
      3: // Acides amin?s digestibles
536
        case ComboBoxAA1.ItemIndex of
537
          0: // Lysine
538
            Cumul := ClientDataSetFeedsLysd.Value;
539
          1: // Thr?onine
540
            Cumul := ClientDataSetFeedsThrd.Value;
541
          2: // M?thionine
542
            Cumul := ClientDataSetFeedsMetd.Value;
543
          3: // Cyst?ine
544
            Cumul := ClientDataSetFeedsCysd.Value;
545
          4: // M?thionine + Cyst?ine
546
            Cumul := ClientDataSetFeedsMetCysd.Value;
547
          5: // Tryptophane
548
            Cumul := ClientDataSetFeedsTrpd.Value;
549
          6: // Isoleucine
550
            Cumul := ClientDataSetFeedsIled.Value;
551
          7: // Valine
552
            Cumul := ClientDataSetFeedsVald.Value;
553
          8: // Leucine
554
            Cumul := ClientDataSetFeedsLeud.Value;
555
          9: // Ph?nylalanine
556
            Cumul := ClientDataSetFeedsPhed.Value;
557
          10: // Tyrosine
558
            Cumul := ClientDataSetFeedsTyrd.Value;
559
          11: // Ph?nylalanine + Tyrosine
560
            Cumul := ClientDataSetFeedsPheTyrd.Value;
561
          12: // Histidine
562
            Cumul := ClientDataSetFeedsHisd.Value;
563
          13: // Arginine
564
            Cumul := ClientDataSetFeedsArgd.Value;
565
          14: // Alanine
566
            Cumul := ClientDataSetFeedsAlad.Value;
567
          15: // Aspartate
568
            Cumul := ClientDataSetFeedsAspd.Value;
569
          16: // Glutamate
570
            Cumul := ClientDataSetFeedsGlud.Value;
571
          17: // Glycine
572
            Cumul := ClientDataSetFeedsGlyd.Value;
573
          18: // S?rine
574
            Cumul := ClientDataSetFeedsSerd.Value;
575
          19: // Proline
576
            Cumul := ClientDataSetFeedsProd.Value;
577
          else
578
            Cumul := 0;
579
        end;
580
      4: // Min?raux
581
        case ComboBoxMinerals1.ItemIndex of
582
          0: // Calcium
583
            Cumul := ClientDataSetFeedsCa.Value;
584
          1: // Phosphore
585
            Cumul := ClientDataSetFeedsP.Value;
586
          2: // Phosphore digestible
587
            Cumul := ClientDataSetFeedsPd.Value;
588
          else
589
            Cumul := 0;
590
        end;
591
      else
592
        Cumul := 0;
593
    end;
594
    if Cumul = 0
595
    then // Division par z?ro
596
      Cumul := 1;
597
    ClientDataSetComposition.First;
598
    Total := 0;
599
    while not ClientDataSetComposition.Eof do
600
    begin
601
      if ClientDataSetCompositionUser.Value
602
      then
603
        ClientDataSetIngredients.Filter := Format('Id = %d and User', [ClientDataSetCompositionIngredient.Value])
604
      else
605
        ClientDataSetIngredients.Filter := Format('Id = %d and not User', [ClientDataSetCompositionIngredient.Value]);
606
      ClientDataSetIngredients.Filtered := True;
607
      IngredientName := StrTrunc(ClientDataSetIngredientsName.Value, 25);
608
      Ratio := InputIncorporation(ClientDataSetCompositionLevel.Value, FormOptions.Incorporation);
609
      if (FormOptions.Expression = 0)
610
      and ((ComboBoxType1.ItemIndex <> 0) or (ComboBoxProximal1.ItemIndex > 1))
611
      then // Conversion frais -> sec (mati?re s?che de la mati?re premi?re) - except? pour Composition et MS
612
        Ratio := Ratio / InputProximal(ClientDataSetIngredientsMS.Value, 1, 1, FormOptions.Proximal);
613
      RapMS := InputProximal(ClientDataSetCompositionMS.Value, 1, 1, FormOptions.Proximal);
614
      if ((ComboBoxType1.ItemIndex <> 0) or (ComboBoxProximal1.ItemIndex > 1))
615
      then // Conversion sec -> frais (mati?re s?che de la composition) - except? pour Composition et MS
616
        Ratio := Ratio * RapMS;
617
      case ComboBoxType1.ItemIndex of
618
        0: // Analyse proximale
619
          case ComboBoxProximal1.ItemIndex of
620
            0: // Composition
621
              Value := OutputProximal(Ratio, 1, 1, FormOptions.Proximal);
622
            1: // MS
623
              Value := ClientDataSetCompositionMS.Value * Ratio;
624
            2: // MM
625
              Value := ClientDataSetIngredientsMM.Value * Ratio;
626
            3: // MAT
627
              Value := ClientDataSetIngredientsMAT.Value * Ratio;
628
            4: // MG
629
              Value := ClientDataSetIngredientsMG.Value * Ratio;
630
            5: // CB
631
              Value := ClientDataSetIngredientsCB.Value * Ratio;
632
            6: // NDF
633
              Value := ClientDataSetIngredientsNDF.Value * Ratio;
634
            7: // ADF
635
              Value := ClientDataSetIngredientsADF.Value * Ratio;
636
            8: // ADL
637
              Value := ClientDataSetIngredientsADL.Value * Ratio;
638
            9: // Amidon
639
              Value := ClientDataSetIngredientsAmidon.Value * Ratio;
640
            10: // Sucres
641
              Value := ClientDataSetIngredientsSucres.Value * Ratio;
642
            else
643
              Value := 0;
644
          end;
645
        1: // Valeurs ?nerg?tiques
646
          case ComboBoxEnergy1.ItemIndex of
647
            0: // Energie brute
648
              Value := ClientDataSetIngredientsEB.Value * Ratio;
649
            1: // Energie digestible (porc croissance)
650
              Value := ClientDataSetIngredientsEDc.Value * Ratio;
651
            2: // Energie digestible (porc adulte)
652
              Value := ClientDataSetIngredientsEDt.Value * Ratio;
653
            3: // Energie m?tabolisable (porc croissance)
654
              Value := ClientDataSetIngredientsEMc.Value * Ratio;
655
            4: // Energie m?tabolisable (porc adulte)
656
              Value := ClientDataSetIngredientsEMt.Value * Ratio;
657
            5: // Energie nette (porc croissance)
658
              Value := ClientDataSetIngredientsENc.Value * Ratio;
659
            6: // Energie nette (porc adulte)
660
              Value := ClientDataSetIngredientsENt.Value * Ratio;
661
            else
662
              Value := 0;
663
          end;
664
        2: // Acides amin?s totaux
665
          case ComboBoxAA1.ItemIndex of
666
            0: // Lysine
667
              Value := ClientDataSetIngredientsLys.Value * Ratio;
668
            1: // Thr?onine
669
              Value := ClientDataSetIngredientsThr.Value * Ratio;
670
            2: // M?thionine
671
              Value := ClientDataSetIngredientsMet.Value * Ratio;
672
            3: // Cyst?ine
673
              Value := ClientDataSetIngredientsCys.Value * Ratio;
674
            4: // M?thionine + Cyst?ine
675
              Value := ClientDataSetIngredientsMetCys.Value * Ratio;
676
            5: // Tryptophane
677
              Value := ClientDataSetIngredientsTrp.Value * Ratio;
678
            6: // Isoleucine
679
              Value := ClientDataSetIngredientsIle.Value * Ratio;
680
            7: // Valine
681
              Value := ClientDataSetIngredientsVal.Value * Ratio;
682
            8: // Leucine
683
              Value := ClientDataSetIngredientsLeu.Value * Ratio;
684
            9: // Ph?nylalanine
685
              Value := ClientDataSetIngredientsPhe.Value * Ratio;
686
            10: // Tyrosine
687
              Value := ClientDataSetIngredientsTyr.Value * Ratio;
688
            11: // Ph?nylalanine + Tyrosine
689
              Value := ClientDataSetIngredientsPheTyr.Value * Ratio;
690
            12: // Histidine
691
              Value := ClientDataSetIngredientsHis.Value * Ratio;
692
            13: // Arginine
693
              Value := ClientDataSetIngredientsArg.Value * Ratio;
694
            14: // Alanine
695
              Value := ClientDataSetIngredientsAla.Value * Ratio;
696
            15: // Aspartate
697
              Value := ClientDataSetIngredientsAsp.Value * Ratio;
698
            16: // Glutamate
699
              Value := ClientDataSetIngredientsGlu.Value * Ratio;
700
            17: // Glycine
701
              Value := ClientDataSetIngredientsGly.Value * Ratio;
702
            18: // S?rine
703
              Value := ClientDataSetIngredientsSer.Value * Ratio;
704
            19: // Proline
705
              Value := ClientDataSetIngredientsPro.Value * Ratio;
706
            else
707
              Value := 0;
708
          end;
709
        3: // Acides amin?s digestibles
710
          case ComboBoxAA1.ItemIndex of
711
            0: // Lysine
712
              Value := ClientDataSetIngredientsLysd.Value * Ratio;
713
            1: // Thr?onine
714
              Value := ClientDataSetIngredientsThrd.Value * Ratio;
715
            2: // M?thionine
716
              Value := ClientDataSetIngredientsMetd.Value * Ratio;
717
            3: // Cyst?ine
718
              Value := ClientDataSetIngredientsCysd.Value * Ratio;
719
            4: // M?thionine + Cyst?ine
720
              Value := ClientDataSetIngredientsMetCysd.Value * Ratio;
721
            5: // Tryptophane
722
              Value := ClientDataSetIngredientsTrpd.Value * Ratio;
723
            6: // Isoleucine
724
              Value := ClientDataSetIngredientsIled.Value * Ratio;
725
            7: // Valine
726
              Value := ClientDataSetIngredientsVald.Value * Ratio;
727
            8: // Leucine
728
              Value := ClientDataSetIngredientsLeud.Value * Ratio;
729
            9: // Ph?nylalanine
730
              Value := ClientDataSetIngredientsPhed.Value * Ratio;
731
            10: // Tyrosine
732
              Value := ClientDataSetIngredientsTyrd.Value * Ratio;
733
            11: // Ph?nylalanine + Tyrosine
734
              Value := ClientDataSetIngredientsPheTyrd.Value * Ratio;
735
            12: // Histidine
736
              Value := ClientDataSetIngredientsHisd.Value * Ratio;
737
            13: // Arginine
738
              Value := ClientDataSetIngredientsArgd.Value * Ratio;
739
            14: // Alanine
740
              Value := ClientDataSetIngredientsAlad.Value * Ratio;
741
            15: // Aspartate
742
              Value := ClientDataSetIngredientsAspd.Value * Ratio;
743
            16: // Glutamate
744
              Value := ClientDataSetIngredientsGlud.Value * Ratio;
745
            17: // Glycine
746
              Value := ClientDataSetIngredientsGlyd.Value * Ratio;
747
            18: // S?rine
748
              Value := ClientDataSetIngredientsSerd.Value * Ratio;
749
            19: // Proline
750
              Value := ClientDataSetIngredientsProd.Value * Ratio;
751
            else
752
              Value := 0;
753
          end;
754
        4: // Min?raux
755
          case ComboBoxMinerals1.ItemIndex of
756
            0: // Calcium
757
              Value := ClientDataSetIngredientsCa.Value * Ratio;
758
            1: // Phosphore
759
              Value := ClientDataSetIngredientsP.Value * Ratio;
760
            2: // Phosphore digestible
761
              if ClientDataSetFeedsPresentation.Value = 0
762
              then // Farine (dPphy)
763
                Value := ClientDataSetIngredientsdPphy.Value / 100 * ClientDataSetIngredientsP.Value * Ratio
764
              else // Granul?s (dP)
765
                Value := ClientDataSetIngredientsdP.Value / 100 * ClientDataSetIngredientsP.Value * Ratio;
766
            else
767
              Value := 0;
768
          end;
769
        else
770
          Value := 0;
771
      end;
772
      if (FormOptions.Expression = 1)
773
      and ((ComboBoxType1.ItemIndex <> 0) or (ComboBoxProximal1.ItemIndex > 1))
774
      then // Conversion frais -> sec (mati?re s?che du r?gime) - except? pour Composition et MS
775
        Value := Value / InputProximal(ClientDataSetFeedsMS.Value, 1, 1, FormOptions.Proximal);
776
      if Value > 0
777
      then // Prendre en compte la valeur
778
      begin
779
        FeedBar := TBarSeries.Create(Chart1);
780
        FeedBar.ParentChart := Chart1;
781
        FeedBar.Title := Format('%s (%1.2f %%)', [IngredientName, Value / Cumul * 100]);
782
        FeedBar.BarPen.Color := FeedBar.SeriesColor;
783
        FeedBar.MultiBar := mbStacked100;
784
        FeedBar.Marks.Visible := False;
785
        Chart1.AddSeries(FeedBar);
786
        FeedBar.AddBar(Value, '', clTeeColor);
787
        Total := Total + Value;
788
      end;
789
      ClientDataSetComposition.Next;
790
    end;
791
    ClientDataSetIngredients.Filtered := False;
792
    ClientDataSetIngredients.Filter := '';
793
    // Cas particuliers
794
    if (ComboBoxType1.ItemIndex = 1)
795
    and ((ComboBoxEnergy1.ItemIndex = 1)
796
      or (ComboBoxEnergy1.ItemIndex = 3)
797
      or (ComboBoxEnergy1.ItemIndex = 5))
798
    and (ClientDataSetFeedsBonusC.Value > 0)
799
    then // Bonus ?nergie (porc croissance)
800
    begin
801
      case ComboBoxEnergy1.ItemIndex of
802
        1: Value := ClientDataSetFeedsEDc.Value - Total;
803
        3: Value := ClientDataSetFeedsEMc.Value - Total;
804
        5: Value := ClientDataSetFeedsENc.Value - Total;
805
        else Value := 0;
806
      end;
807
      FeedBar := TBarSeries.Create(Chart1);
808
      FeedBar.ParentChart := Chart1;
809
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Energy bonus'), Value / Cumul * 100]);
810
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
811
      FeedBar.MultiBar := mbStacked100;
812
      FeedBar.Marks.Visible := False;
813
      Chart1.AddSeries(FeedBar);
814
      FeedBar.AddBar(Value, '', clTeeColor);
815
      Total := Total + Value;
816
    end;
817
    if (ComboBoxType1.ItemIndex = 1)
818
    and ((ComboBoxEnergy1.ItemIndex = 2)
819
      or (ComboBoxEnergy1.ItemIndex = 4)
820
      or (ComboBoxEnergy1.ItemIndex = 6))
821
    and (ClientDataSetFeedsBonusT.Value > 0)
822
    then // Bonus ?nergie (porc adulte)
823
    begin
824
      case ComboBoxEnergy1.ItemIndex of
825
        2: Value := ClientDataSetFeedsEDt.Value - Total;
826
        4: Value := ClientDataSetFeedsEMt.Value - Total;
827
        6: Value := ClientDataSetFeedsENt.Value - Total;
828
        else Value := 0;
829
      end;
830
      FeedBar := TBarSeries.Create(Chart1);
831
      FeedBar.ParentChart := Chart1;
832
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Energy bonus'), Value / Cumul * 100]);
833
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
834
      FeedBar.MultiBar := mbStacked100;
835
      FeedBar.Marks.Visible := False;
836
      Chart1.AddSeries(FeedBar);
837
      FeedBar.AddBar(Value, '', clTeeColor);
838
      Total := Total + Value;
839
    end;
840
    if (ComboBoxType1.ItemIndex = 0)
841
    and (ComboBoxProximal1.ItemIndex = 0)
842
    and not ClientDataSetFeedsPhytaseId.IsNull
843
    and (ClientDataSetFeedsPhytaseLevel.Value > 0)
844
    then // Phytase (taux d'incorporation)
845
    begin
846
      Ratio := InputIncorporation(ClientDataSetFeedsPhytaseLevel.Value, FormOptions.Incorporation);
847
      Value := OutputProximal(Ratio, 1, 1, FormOptions.Proximal);
848
      FeedBar := TBarSeries.Create(Chart1);
849
      FeedBar.ParentChart := Chart1;
850
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Phytase'), Value / Cumul * 100]);
851
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
852
      FeedBar.MultiBar := mbStacked100;
853
      FeedBar.Marks.Visible := False;
854
      Chart1.AddSeries(FeedBar);
855
      FeedBar.AddBar(Value, '', clTeeColor);
856
      Total := Total + Value;
857
    end;
858
    if (ComboBoxType1.ItemIndex = 4)
859
    and (ComboBoxMinerals1.ItemIndex = 2)
860
    and not ClientDataSetFeedsPhytaseId.IsNull
861
    and (ClientDataSetFeedsPd.Value > Total)
862
    then // Phytase (Phosphore digestible)
863
    begin
864
      Value := ClientDataSetFeedsPd.Value - Total;
865
      FeedBar := TBarSeries.Create(Chart1);
866
      FeedBar.ParentChart := Chart1;
867
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Phytase'), Value / Cumul * 100]);
868
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
869
      FeedBar.MultiBar := mbStacked100;
870
      FeedBar.Marks.Visible := False;
871
      Chart1.AddSeries(FeedBar);
872
      FeedBar.AddBar(Value, '', clTeeColor);
873
      Total := Total + Value;
874
    end;
875
    // Total
876
    case ComboBoxType1.ItemIndex of
877
      0: // Analyse proximale
878
        if (FormOptions.Expression = 0) or (ComboBoxProximal1.ItemIndex < 2)
879
        then // sur frais
880
          Chart1.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.ProximalDecimals, Total, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal]]))
881
        else // sur mati?re s?che - except? pour Composition et MS
882
          Chart1.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.ProximalDecimals, Total, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]));
883
      1: // Valeurs ?nerg?tiques
884
        if FormOptions.Expression = 0
885
        then // sur frais
886
          Chart1.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.EnergyDecimals, Total, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy]]))
887
        else // sur mati?re s?che
888
          Chart1.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.EnergyDecimals, Total, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]));
889
      2, 3: // Acides amin?s
890
        if FormOptions.Expression = 0
891
        then // sur frais
892
          Chart1.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.AADecimals, Total, FormOptions.ComboBoxAA.Items[FormOptions.AA]]))
893
        else // sur mati?re s?che
894
          Chart1.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.AADecimals, Total, FormOptions.ComboBoxAA.Items[FormOptions.AA], _('DM')]));
895
      4: // Min?raux
896
        if FormOptions.Expression = 0
897
        then // sur frais
898
          Chart1.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.MineralsDecimals, Total, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals]]))
899
        else // sur mati?re s?che
900
          Chart1.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.MineralsDecimals, Total, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], _('DM')]));
901
    end;
902
  end;
903
end;
904
905
procedure TFormFeedCharts.ComboBoxOption2Change(Sender: TObject);
906
var
907
  IngredientName: String;
908
  Cumul, Ratio, Total, Value: Double;
909
  FeedBar: TBarSeries;
910
begin
911
//  while Chart2.SeriesCount > 0 do
912
//    Chart2.Series[0].Free;
913
  Chart2.FreeAllSeries(nil);
914
  Chart2.SubTitle.Clear;
915
  with DataModuleDeclaration do
916
  begin
917
    Chart2.AxisVisible := True;
918
    Chart2.SubTitle.Text.Add(ComboBoxType2.Text);
919
    case ComboBoxType2.ItemIndex of
920
      0: // Analyse proximale
921
        Chart2.SubTitle.Text.Add(ComboBoxProximal2.Text);
922
      1: // Valeurs ?nerg?tiques
923
        Chart2.SubTitle.Text.Add(ComboBoxEnergy2.Text);
924
      2, 3: // Acides amin?s
925
        Chart2.SubTitle.Text.Add(ComboBoxAA2.Text);
926
      4: // Min?raux
927
        Chart2.SubTitle.Text.Add(ComboBoxMinerals2.Text);
928
    end;
929
    case ComboBoxType2.ItemIndex of
930
      0: // Analyse proximale
931
        case ComboBoxProximal2.ItemIndex of
932
          0: // Composition
933
            Cumul := OutputIncorporation(1, FormOptions.Incorporation);
934
          1: // MS
935
            Cumul := ClientDataSetFeedsMS.Value;
936
          2: // MM
937
            Cumul := ClientDataSetFeedsMM.Value;
938
          3: // MAT
939
            Cumul := ClientDataSetFeedsMAT.Value;
940
          4: // MG
941
            Cumul := ClientDataSetFeedsMG.Value;
942
          5: // CB
943
            Cumul := ClientDataSetFeedsCB.Value;
944
          6: // NDF
945
            Cumul := ClientDataSetFeedsNDF.Value;
946
          7: // ADF
947
            Cumul := ClientDataSetFeedsADF.Value;
948
          8: // ADL
949
            Cumul := ClientDataSetFeedsADL.Value;
950
          9: // Amidon
951
            Cumul := ClientDataSetFeedsAmidon.Value;
952
          10: // Sucres
953
            Cumul := ClientDataSetFeedsSucres.Value;
954
          else
955
            Cumul := 0;
956
        end;
957
      1: // Valeurs ?nerg?tiques
958
        case ComboBoxEnergy2.ItemIndex of
959
          0: // Energie brute
960
            Cumul := ClientDataSetFeedsEB.Value;
961
          1: // Energie digestible (porc croissance)
962
            Cumul := ClientDataSetFeedsEDc.Value;
963
          2: // Energie digestible (porc adulte)
964
            Cumul := ClientDataSetFeedsEDt.Value;
965
          3: // Energie m?tabolisable (porc croissance)
966
            Cumul := ClientDataSetFeedsEMc.Value;
967
          4: // Energie m?tabolisable (porc adulte)
968
            Cumul := ClientDataSetFeedsEMt.Value;
969
          5: // Energie nette (porc croissance)
970
            Cumul := ClientDataSetFeedsENc.Value;
971
          6: // Energie nette (porc adulte)
972
            Cumul := ClientDataSetFeedsENt.Value;
973
          else
974
            Cumul := 0;
975
        end;
976
      2: // Acides amin?s totaux
977
        case ComboBoxAA2.ItemIndex of
978
          0: // Lysine
979
            Cumul := ClientDataSetFeedsLys.Value;
980
          1: // Thr?onine
981
            Cumul := ClientDataSetFeedsThr.Value;
982
          2: // M?thionine
983
            Cumul := ClientDataSetFeedsMet.Value;
984
          3: // Cyst?ine
985
            Cumul := ClientDataSetFeedsCys.Value;
986
          4: // M?thionine + Cyst?ine
987
            Cumul := ClientDataSetFeedsMetCys.Value;
988
          5: // Tryptophane
989
            Cumul := ClientDataSetFeedsTrp.Value;
990
          6: // Isoleucine
991
            Cumul := ClientDataSetFeedsIle.Value;
992
          7: // Valine
993
            Cumul := ClientDataSetFeedsVal.Value;
994
          8: // Leucine
995
            Cumul := ClientDataSetFeedsLeu.Value;
996
          9: // Ph?nylalanine
997
            Cumul := ClientDataSetFeedsPhe.Value;
998
          10: // Tyrosine
999
            Cumul := ClientDataSetFeedsTyr.Value;
1000
          11: // Ph?nylalanine + Tyrosine
1001
            Cumul := ClientDataSetFeedsPheTyr.Value;
1002
          12: // Histidine
1003
            Cumul := ClientDataSetFeedsHis.Value;
1004
          13: // Arginine
1005
            Cumul := ClientDataSetFeedsArg.Value;
1006
          14: // Alanine
1007
            Cumul := ClientDataSetFeedsAla.Value;
1008
          15: // Aspartate
1009
            Cumul := ClientDataSetFeedsAsp.Value;
1010
          16: // Glutamate
1011
            Cumul := ClientDataSetFeedsGlu.Value;
1012
          17: // Glycine
1013
            Cumul := ClientDataSetFeedsGly.Value;
1014
          18: // S?rine
1015
            Cumul := ClientDataSetFeedsSer.Value;
1016
          19: // Proline
1017
            Cumul := ClientDataSetFeedsPro.Value;
1018
          else
1019
            Cumul := 0;
1020
        end;
1021
      3: // Acides amin?s digestibles
1022
        case ComboBoxAA2.ItemIndex of
1023
          0: // Lysine
1024
            Cumul := ClientDataSetFeedsLysd.Value;
1025
          1: // Thr?onine
1026
            Cumul := ClientDataSetFeedsThrd.Value;
1027
          2: // M?thionine
1028
            Cumul := ClientDataSetFeedsMetd.Value;
1029
          3: // Cyst?ine
1030
            Cumul := ClientDataSetFeedsCysd.Value;
1031
          4: // M?thionine + Cyst?ine
1032
            Cumul := ClientDataSetFeedsMetCysd.Value;
1033
          5: // Tryptophane
1034
            Cumul := ClientDataSetFeedsTrpd.Value;
1035
          6: // Isoleucine
1036
            Cumul := ClientDataSetFeedsIled.Value;
1037
          7: // Valine
1038
            Cumul := ClientDataSetFeedsVald.Value;
1039
          8: // Leucine
1040
            Cumul := ClientDataSetFeedsLeud.Value;
1041
          9: // Ph?nylalanine
1042
            Cumul := ClientDataSetFeedsPhed.Value;
1043
          10: // Tyrosine
1044
            Cumul := ClientDataSetFeedsTyrd.Value;
1045
          11: // Ph?nylalanine + Tyrosine
1046
            Cumul := ClientDataSetFeedsPheTyrd.Value;
1047
          12: // Histidine
1048
            Cumul := ClientDataSetFeedsHisd.Value;
1049
          13: // Arginine
1050
            Cumul := ClientDataSetFeedsArgd.Value;
1051
          14: // Alanine
1052
            Cumul := ClientDataSetFeedsAlad.Value;
1053
          15: // Aspartate
1054
            Cumul := ClientDataSetFeedsAspd.Value;
1055
          16: // Glutamate
1056
            Cumul := ClientDataSetFeedsGlud.Value;
1057
          17: // Glycine
1058
            Cumul := ClientDataSetFeedsGlyd.Value;
1059
          18: // S?rine
1060
            Cumul := ClientDataSetFeedsSerd.Value;
1061
          19: // Proline
1062
            Cumul := ClientDataSetFeedsProd.Value;
1063
          else
1064
            Cumul := 0;
1065
        end;
1066
      4: // Min?raux
1067
        case ComboBoxMinerals2.ItemIndex of
1068
          0: // Calcium
1069
            Cumul := ClientDataSetFeedsCa.Value;
1070
          1: // Phosphore
1071
            Cumul := ClientDataSetFeedsP.Value;
1072
          2: // Phosphore digestible
1073
            Cumul := ClientDataSetFeedsPd.Value;
1074
          else
1075
            Cumul := 0;
1076
        end;
1077
      else
1078
        Cumul := 0;
1079
    end;
1080
    if Cumul = 0
1081
    then // Division par z?ro
1082
      Cumul := 1;
1083
    ClientDataSetComposition.First;
1084
    Total := 0;
1085
    while not ClientDataSetComposition.Eof do
1086
    begin
1087
      if ClientDataSetCompositionUser.Value
1088
      then
1089
        ClientDataSetIngredients.Filter := Format('Id = %d and User', [ClientDataSetCompositionIngredient.Value])
1090
      else
1091
        ClientDataSetIngredients.Filter := Format('Id = %d and not User', [ClientDataSetCompositionIngredient.Value]);
1092
      ClientDataSetIngredients.Filtered := True;
1093
      IngredientName := StrTrunc(ClientDataSetIngredientsName.Value, 25);
1094
      Ratio := InputIncorporation(ClientDataSetCompositionLevel.Value, FormOptions.Incorporation);
1095
      if (FormOptions.Expression = 0)
1096
      and ((ComboBoxType2.ItemIndex <> 0) or (ComboBoxProximal2.ItemIndex > 1))
1097
      then // Conversion frais -> sec (mati?re s?che de la mati?re premi?re) - except? pour Composition et MS
1098
        Ratio := Ratio / InputProximal(ClientDataSetIngredientsMS.Value, 1, 1, FormOptions.Proximal);
1099
      RapMS := InputProximal(ClientDataSetCompositionMS.Value, 1, 1, FormOptions.Proximal);
1100
      if ((ComboBoxType2.ItemIndex <> 0) or (ComboBoxProximal2.ItemIndex > 1))
1101
      then // Conversion sec -> frais (mati?re s?che de la composition) - except? pour Composition et MS
1102
        Ratio := Ratio * RapMS;
1103
      case ComboBoxType2.ItemIndex of
1104
        0: // Analyse proximale
1105
          case ComboBoxProximal2.ItemIndex of
1106
            0: // Composition
1107
              Value := OutputProximal(Ratio, 1, 1, FormOptions.Proximal);
1108
            1: // MS
1109
              Value := ClientDataSetCompositionMS.Value * Ratio;
1110
            2: // MM
1111
              Value := ClientDataSetIngredientsMM.Value * Ratio;
1112
            3: // MAT
1113
              Value := ClientDataSetIngredientsMAT.Value * Ratio;
1114
            4: // MG
1115
              Value := ClientDataSetIngredientsMG.Value * Ratio;
1116
            5: // CB
1117
              Value := ClientDataSetIngredientsCB.Value * Ratio;
1118
            6: // NDF
1119
              Value := ClientDataSetIngredientsNDF.Value * Ratio;
1120
            7: // ADF
1121
              Value := ClientDataSetIngredientsADF.Value * Ratio;
1122
            8: // ADL
1123
              Value := ClientDataSetIngredientsADL.Value * Ratio;
1124
            9: // Amidon
1125
              Value := ClientDataSetIngredientsAmidon.Value * Ratio;
1126
            10: // Sucres
1127
              Value := ClientDataSetIngredientsSucres.Value * Ratio;
1128
            else
1129
              Value := 0;
1130
          end;
1131
        1: // Valeurs ?nerg?tiques
1132
          case ComboBoxEnergy2.ItemIndex of
1133
            0: // Energie brute
1134
              Value := ClientDataSetIngredientsEB.Value * Ratio;
1135
            1: // Energie digestible (porc croissance)
1136
              Value := ClientDataSetIngredientsEDc.Value * Ratio;
1137
            2: // Energie digestible (porc adulte)
1138
              Value := ClientDataSetIngredientsEDt.Value * Ratio;
1139
            3: // Energie m?tabolisable (porc croissance)
1140
              Value := ClientDataSetIngredientsEMc.Value * Ratio;
1141
            4: // Energie m?tabolisable (porc adulte)
1142
              Value := ClientDataSetIngredientsEMt.Value * Ratio;
1143
            5: // Energie nette (porc croissance)
1144
              Value := ClientDataSetIngredientsENc.Value * Ratio;
1145
            6: // Energie nette (porc adulte)
1146
              Value := ClientDataSetIngredientsENt.Value * Ratio;
1147
            else
1148
              Value := 0;
1149
          end;
1150
        2: // Acides amin?s totaux
1151
          case ComboBoxAA2.ItemIndex of
1152
            0: // Lysine
1153
              Value := ClientDataSetIngredientsLys.Value * Ratio;
1154
            1: // Thr?onine
1155
              Value := ClientDataSetIngredientsThr.Value * Ratio;
1156
            2: // M?thionine
1157
              Value := ClientDataSetIngredientsMet.Value * Ratio;
1158
            3: // Cyst?ine
1159
              Value := ClientDataSetIngredientsCys.Value * Ratio;
1160
            4: // M?thionine + Cyst?ine
1161
              Value := ClientDataSetIngredientsMetCys.Value * Ratio;
1162
            5: // Tryptophane
1163
              Value := ClientDataSetIngredientsTrp.Value * Ratio;
1164
            6: // Isoleucine
1165
              Value := ClientDataSetIngredientsIle.Value * Ratio;
1166
            7: // Valine
1167
              Value := ClientDataSetIngredientsVal.Value * Ratio;
1168
            8: // Leucine
1169
              Value := ClientDataSetIngredientsLeu.Value * Ratio;
1170
            9: // Ph?nylalanine
1171
              Value := ClientDataSetIngredientsPhe.Value * Ratio;
1172
            10: // Tyrosine
1173
              Value := ClientDataSetIngredientsTyr.Value * Ratio;
1174
            11: // Ph?nylalanine + Tyrosine
1175
              Value := ClientDataSetIngredientsPheTyr.Value * Ratio;
1176
            12: // Histidine
1177
              Value := ClientDataSetIngredientsHis.Value * Ratio;
1178
            13: // Arginine
1179
              Value := ClientDataSetIngredientsArg.Value * Ratio;
1180
            14: // Alanine
1181
              Value := ClientDataSetIngredientsAla.Value * Ratio;
1182
            15: // Aspartate
1183
              Value := ClientDataSetIngredientsAsp.Value * Ratio;
1184
            16: // Glutamate
1185
              Value := ClientDataSetIngredientsGlu.Value * Ratio;
1186
            17: // Glycine
1187
              Value := ClientDataSetIngredientsGly.Value * Ratio;
1188
            18: // S?rine
1189
              Value := ClientDataSetIngredientsSer.Value * Ratio;
1190
            19: // Proline
1191
              Value := ClientDataSetIngredientsPro.Value * Ratio;
1192
            else
1193
              Value := 0;
1194
          end;
1195
        3: // Acides amin?s digestibles
1196
          case ComboBoxAA2.ItemIndex of
1197
            0: // Lysine
1198
              Value := ClientDataSetIngredientsLysd.Value * Ratio;
1199
            1: // Thr?onine
1200
              Value := ClientDataSetIngredientsThrd.Value * Ratio;
1201
            2: // M?thionine
1202
              Value := ClientDataSetIngredientsMetd.Value * Ratio;
1203
            3: // Cyst?ine
1204
              Value := ClientDataSetIngredientsCysd.Value * Ratio;
1205
            4: // M?thionine + Cyst?ine
1206
              Value := ClientDataSetIngredientsMetCysd.Value * Ratio;
1207
            5: // Tryptophane
1208
              Value := ClientDataSetIngredientsTrpd.Value * Ratio;
1209
            6: // Isoleucine
1210
              Value := ClientDataSetIngredientsIled.Value * Ratio;
1211
            7: // Valine
1212
              Value := ClientDataSetIngredientsVald.Value * Ratio;
1213
            8: // Leucine
1214
              Value := ClientDataSetIngredientsLeud.Value * Ratio;
1215
            9: // Ph?nylalanine
1216
              Value := ClientDataSetIngredientsPhed.Value * Ratio;
1217
            10: // Tyrosine
1218
              Value := ClientDataSetIngredientsTyrd.Value * Ratio;
1219
            11: // Ph?nylalanine + Tyrosine
1220
              Value := ClientDataSetIngredientsPheTyrd.Value * Ratio;
1221
            12: // Histidine
1222
              Value := ClientDataSetIngredientsHisd.Value * Ratio;
1223
            13: // Arginine
1224
              Value := ClientDataSetIngredientsArgd.Value * Ratio;
1225
            14: // Alanine
1226
              Value := ClientDataSetIngredientsAlad.Value * Ratio;
1227
            15: // Aspartate
1228
              Value := ClientDataSetIngredientsAspd.Value * Ratio;
1229
            16: // Glutamate
1230
              Value := ClientDataSetIngredientsGlud.Value * Ratio;
1231
            17: // Glycine
1232
              Value := ClientDataSetIngredientsGlyd.Value * Ratio;
1233
            18: // S?rine
1234
              Value := ClientDataSetIngredientsSerd.Value * Ratio;
1235
            19: // Proline
1236
              Value := ClientDataSetIngredientsProd.Value * Ratio;
1237
            else
1238
              Value := 0;
1239
          end;
1240
        4: // Min?raux
1241
          case ComboBoxMinerals2.ItemIndex of
1242
            0: // Calcium
1243
              Value := ClientDataSetIngredientsCa.Value * Ratio;
1244
            1: // Phosphore
1245
              Value := ClientDataSetIngredientsP.Value * Ratio;
1246
            2: // Phosphore digestible
1247
              if ClientDataSetFeedsPresentation.Value = 0
1248
              then // Farine (dPphy)
1249
                Value := ClientDataSetIngredientsdPphy.Value / 100 * ClientDataSetIngredientsP.Value * Ratio
1250
              else // Granul?s (dP)
1251
                Value := ClientDataSetIngredientsdP.Value / 100 * ClientDataSetIngredientsP.Value * Ratio;
1252
            else
1253
              Value := 0;
1254
          end;
1255
        else
1256
          Value := 0;
1257
      end;
1258
      if (FormOptions.Expression = 1)
1259
      and ((ComboBoxType2.ItemIndex <> 0) or (ComboBoxProximal2.ItemIndex > 1))
1260
      then // Conversion frais -> sec (mati?re s?che du r?gime) - except? pour Composition et MS
1261
        Value := Value / InputProximal(ClientDataSetFeedsMS.Value, 1, 1, FormOptions.Proximal);
1262
      if Value > 0
1263
      then // Prendre en compte la valeur
1264
      begin
1265
        FeedBar := TBarSeries.Create(Chart2);
1266
        FeedBar.ParentChart := Chart2;
1267
        FeedBar.Title := Format('%s (%1.2f %%)', [IngredientName, Value / Cumul * 100]);
1268
        FeedBar.BarPen.Color := FeedBar.SeriesColor;
1269
        FeedBar.MultiBar := mbStacked100;
1270
        FeedBar.Marks.Visible := False;
1271
        Chart2.AddSeries(FeedBar);
1272
        FeedBar.AddBar(Value, '', clTeeColor);
1273
        Total := Total + Value;
1274
      end;
1275
      ClientDataSetComposition.Next;
1276
    end;
1277
    ClientDataSetIngredients.Filtered := False;
1278
    ClientDataSetIngredients.Filter := '';
1279
    // Cas particuliers
1280
    if (ComboBoxType2.ItemIndex = 1)
1281
    and ((ComboBoxEnergy2.ItemIndex = 1)
1282
      or (ComboBoxEnergy2.ItemIndex = 3)
1283
      or (ComboBoxEnergy2.ItemIndex = 5))
1284
    and (ClientDataSetFeedsBonusC.Value > 0)
1285
    then // Bonus ?nergie (porc croissance)
1286
    begin
1287
      case ComboBoxEnergy2.ItemIndex of
1288
        1: Value := ClientDataSetFeedsEDc.Value - Total;
1289
        3: Value := ClientDataSetFeedsEMc.Value - Total;
1290
        5: Value := ClientDataSetFeedsENc.Value - Total;
1291
        else Value := 0;
1292
      end;
1293
      FeedBar := TBarSeries.Create(Chart2);
1294
      FeedBar.ParentChart := Chart2;
1295
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Energy bonus'), Value / Cumul * 100]);
1296
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
1297
      FeedBar.MultiBar := mbStacked100;
1298
      FeedBar.Marks.Visible := False;
1299
      Chart2.AddSeries(FeedBar);
1300
      FeedBar.AddBar(Value, '', clTeeColor);
1301
      Total := Total + Value;
1302
    end;
1303
    if (ComboBoxType2.ItemIndex = 1)
1304
    and ((ComboBoxEnergy2.ItemIndex = 2)
1305
      or (ComboBoxEnergy2.ItemIndex = 4)
1306
      or (ComboBoxEnergy2.ItemIndex = 6))
1307
    and (ClientDataSetFeedsBonusT.Value > 0)
1308
    then // Bonus ?nergie (porc adulte)
1309
    begin
1310
      case ComboBoxEnergy2.ItemIndex of
1311
        2: Value := ClientDataSetFeedsEDt.Value - Total;
1312
        4: Value := ClientDataSetFeedsEMt.Value - Total;
1313
        6: Value := ClientDataSetFeedsENt.Value - Total;
1314
        else Value := 0;
1315
      end;
1316
      FeedBar := TBarSeries.Create(Chart2);
1317
      FeedBar.ParentChart := Chart2;
1318
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Energy bonus'), Value / Cumul * 100]);
1319
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
1320
      FeedBar.MultiBar := mbStacked100;
1321
      FeedBar.Marks.Visible := False;
1322
      Chart2.AddSeries(FeedBar);
1323
      FeedBar.AddBar(Value, '', clTeeColor);
1324
      Total := Total + Value;
1325
    end;
1326
    if (ComboBoxType2.ItemIndex = 0)
1327
    and (ComboBoxProximal2.ItemIndex = 0)
1328
    and not ClientDataSetFeedsPhytaseId.IsNull
1329
    and (ClientDataSetFeedsPhytaseLevel.Value > 0)
1330
    then // Phytase (taux d'incorporation)
1331
    begin
1332
      Ratio := InputIncorporation(ClientDataSetFeedsPhytaseLevel.Value, FormOptions.Incorporation);
1333
      Value := OutputProximal(Ratio, 1, 1, FormOptions.Proximal);
1334
      FeedBar := TBarSeries.Create(Chart2);
1335
      FeedBar.ParentChart := Chart2;
1336
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Phytase'), Value / Cumul * 100]);
1337
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
1338
      FeedBar.MultiBar := mbStacked100;
1339
      FeedBar.Marks.Visible := False;
1340
      Chart2.AddSeries(FeedBar);
1341
      FeedBar.AddBar(Value, '', clTeeColor);
1342
      Total := Total + Value;
1343
    end;
1344
    if (ComboBoxType2.ItemIndex = 4)
1345
    and (ComboBoxMinerals2.ItemIndex = 2)
1346
    and not ClientDataSetFeedsPhytaseId.IsNull
1347
    and (ClientDataSetFeedsPd.Value > Total)
1348
    then // Phytase (Phosphore digestible)
1349
    begin
1350
      Value := ClientDataSetFeedsPd.Value - Total;
1351
      FeedBar := TBarSeries.Create(Chart2);
1352
      FeedBar.ParentChart := Chart2;
1353
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Phytase'), Value / Cumul * 100]);
1354
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
1355
      FeedBar.MultiBar := mbStacked100;
1356
      FeedBar.Marks.Visible := False;
1357
      Chart2.AddSeries(FeedBar);
1358
      FeedBar.AddBar(Value, '', clTeeColor);
1359
      Total := Total + Value;
1360
    end;
1361
    // Total
1362
    case ComboBoxType2.ItemIndex of
1363
      0: // Analyse proximale
1364
        if (FormOptions.Expression = 0) or (ComboBoxProximal2.ItemIndex < 2)
1365
        then // sur frais
1366
          Chart2.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.ProximalDecimals, Total, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal]]))
1367
        else // sur mati?re s?che - except? pour Composition et MS
1368
          Chart2.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.ProximalDecimals, Total, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]));
1369
      1: // Valeurs ?nerg?tiques
1370
        if FormOptions.Expression = 0
1371
        then // sur frais
1372
          Chart2.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.EnergyDecimals, Total, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy]]))
1373
        else // sur mati?re s?che
1374
          Chart2.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.EnergyDecimals, Total, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]));
1375
      2, 3: // Acides amin?s
1376
        if FormOptions.Expression = 0
1377
        then // sur frais
1378
          Chart2.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.AADecimals, Total, FormOptions.ComboBoxAA.Items[FormOptions.AA]]))
1379
        else // sur mati?re s?che
1380
          Chart2.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.AADecimals, Total, FormOptions.ComboBoxAA.Items[FormOptions.AA], _('DM')]));
1381
      4: // Min?raux
1382
        if FormOptions.Expression = 0
1383
        then // sur frais
1384
          Chart2.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.MineralsDecimals, Total, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals]]))
1385
        else // sur mati?re s?che
1386
          Chart2.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.MineralsDecimals, Total, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], _('DM')]));
1387
    end;
1388
  end;
1389
end;
1390
1391
procedure TFormFeedCharts.ComboBoxOption3Change(Sender: TObject);
1392
var
1393
  IngredientName: String;
1394
  Cumul, Ratio, Total, Value: Double;
1395
  FeedBar: TBarSeries;
1396
begin
1397
//  while Chart3.SeriesCount > 0 do
1398
//    Chart3.Series[0].Free;
1399
  Chart3.FreeAllSeries(nil);
1400
  Chart3.SubTitle.Clear;
1401
  with DataModuleDeclaration do
1402
  begin
1403
    Chart3.AxisVisible := True;
1404
    Chart3.SubTitle.Text.Add(ComboBoxType3.Text);
1405
    case ComboBoxType3.ItemIndex of
1406
      0: // Analyse proximale
1407
        Chart3.SubTitle.Text.Add(ComboBoxProximal3.Text);
1408
      1: // Valeurs ?nerg?tiques
1409
        Chart3.SubTitle.Text.Add(ComboBoxEnergy3.Text);
1410
      2, 3: // Acides amin?s
1411
        Chart3.SubTitle.Text.Add(ComboBoxAA3.Text);
1412
      4: // Min?raux
1413
        Chart3.SubTitle.Text.Add(ComboBoxMinerals3.Text);
1414
    end;
1415
    case ComboBoxType3.ItemIndex of
1416
      0: // Analyse proximale
1417
        case ComboBoxProximal3.ItemIndex of
1418
          0: // Composition
1419
            Cumul := OutputIncorporation(1, FormOptions.Incorporation);
1420
          1: // MS
1421
            Cumul := ClientDataSetFeedsMS.Value;
1422
          2: // MM
1423
            Cumul := ClientDataSetFeedsMM.Value;
1424
          3: // MAT
1425
            Cumul := ClientDataSetFeedsMAT.Value;
1426
          4: // MG
1427
            Cumul := ClientDataSetFeedsMG.Value;
1428
          5: // CB
1429
            Cumul := ClientDataSetFeedsCB.Value;
1430
          6: // NDF
1431
            Cumul := ClientDataSetFeedsNDF.Value;
1432
          7: // ADF
1433
            Cumul := ClientDataSetFeedsADF.Value;
1434
          8: // ADL
1435
            Cumul := ClientDataSetFeedsADL.Value;
1436
          9: // Amidon
1437
            Cumul := ClientDataSetFeedsAmidon.Value;
1438
          10: // Sucres
1439
            Cumul := ClientDataSetFeedsSucres.Value;
1440
          else
1441
            Cumul := 0;
1442
        end;
1443
      1: // Valeurs ?nerg?tiques
1444
        case ComboBoxEnergy3.ItemIndex of
1445
          0: // Energie brute
1446
            Cumul := ClientDataSetFeedsEB.Value;
1447
          1: // Energie digestible (porc croissance)
1448
            Cumul := ClientDataSetFeedsEDc.Value;
1449
          2: // Energie digestible (porc adulte)
1450
            Cumul := ClientDataSetFeedsEDt.Value;
1451
          3: // Energie m?tabolisable (porc croissance)
1452
            Cumul := ClientDataSetFeedsEMc.Value;
1453
          4: // Energie m?tabolisable (porc adulte)
1454
            Cumul := ClientDataSetFeedsEMt.Value;
1455
          5: // Energie nette (porc croissance)
1456
            Cumul := ClientDataSetFeedsENc.Value;
1457
          6: // Energie nette (porc adulte)
1458
            Cumul := ClientDataSetFeedsENt.Value;
1459
          else
1460
            Cumul := 0;
1461
        end;
1462
      2: // Acides amin?s totaux
1463
        case ComboBoxAA3.ItemIndex of
1464
          0: // Lysine
1465
            Cumul := ClientDataSetFeedsLys.Value;
1466
          1: // Thr?onine
1467
            Cumul := ClientDataSetFeedsThr.Value;
1468
          2: // M?thionine
1469
            Cumul := ClientDataSetFeedsMet.Value;
1470
          3: // Cyst?ine
1471
            Cumul := ClientDataSetFeedsCys.Value;
1472
          4: // M?thionine + Cyst?ine
1473
            Cumul := ClientDataSetFeedsMetCys.Value;
1474
          5: // Tryptophane
1475
            Cumul := ClientDataSetFeedsTrp.Value;
1476
          6: // Isoleucine
1477
            Cumul := ClientDataSetFeedsIle.Value;
1478
          7: // Valine
1479
            Cumul := ClientDataSetFeedsVal.Value;
1480
          8: // Leucine
1481
            Cumul := ClientDataSetFeedsLeu.Value;
1482
          9: // Ph?nylalanine
1483
            Cumul := ClientDataSetFeedsPhe.Value;
1484
          10: // Tyrosine
1485
            Cumul := ClientDataSetFeedsTyr.Value;
1486
          11: // Ph?nylalanine + Tyrosine
1487
            Cumul := ClientDataSetFeedsPheTyr.Value;
1488
          12: // Histidine
1489
            Cumul := ClientDataSetFeedsHis.Value;
1490
          13: // Arginine
1491
            Cumul := ClientDataSetFeedsArg.Value;
1492
          14: // Alanine
1493
            Cumul := ClientDataSetFeedsAla.Value;
1494
          15: // Aspartate
1495
            Cumul := ClientDataSetFeedsAsp.Value;
1496
          16: // Glutamate
1497
            Cumul := ClientDataSetFeedsGlu.Value;
1498
          17: // Glycine
1499
            Cumul := ClientDataSetFeedsGly.Value;
1500
          18: // S?rine
1501
            Cumul := ClientDataSetFeedsSer.Value;
1502
          19: // Proline
1503
            Cumul := ClientDataSetFeedsPro.Value;
1504
          else
1505
            Cumul := 0;
1506
        end;
1507
      3: // Acides amin?s digestibles
1508
        case ComboBoxAA3.ItemIndex of
1509
          0: // Lysine
1510
            Cumul := ClientDataSetFeedsLysd.Value;
1511
          1: // Thr?onine
1512
            Cumul := ClientDataSetFeedsThrd.Value;
1513
          2: // M?thionine
1514
            Cumul := ClientDataSetFeedsMetd.Value;
1515
          3: // Cyst?ine
1516
            Cumul := ClientDataSetFeedsCysd.Value;
1517
          4: // M?thionine + Cyst?ine
1518
            Cumul := ClientDataSetFeedsMetCysd.Value;
1519
          5: // Tryptophane
1520
            Cumul := ClientDataSetFeedsTrpd.Value;
1521
          6: // Isoleucine
1522
            Cumul := ClientDataSetFeedsIled.Value;
1523
          7: // Valine
1524
            Cumul := ClientDataSetFeedsVald.Value;
1525
          8: // Leucine
1526
            Cumul := ClientDataSetFeedsLeud.Value;
1527
          9: // Ph?nylalanine
1528
            Cumul := ClientDataSetFeedsPhed.Value;
1529
          10: // Tyrosine
1530
            Cumul := ClientDataSetFeedsTyrd.Value;
1531
          11: // Ph?nylalanine + Tyrosine
1532
            Cumul := ClientDataSetFeedsPheTyrd.Value;
1533
          12: // Histidine
1534
            Cumul := ClientDataSetFeedsHisd.Value;
1535
          13: // Arginine
1536
            Cumul := ClientDataSetFeedsArgd.Value;
1537
          14: // Alanine
1538
            Cumul := ClientDataSetFeedsAlad.Value;
1539
          15: // Aspartate
1540
            Cumul := ClientDataSetFeedsAspd.Value;
1541
          16: // Glutamate
1542
            Cumul := ClientDataSetFeedsGlud.Value;
1543
          17: // Glycine
1544
            Cumul := ClientDataSetFeedsGlyd.Value;
1545
          18: // S?rine
1546
            Cumul := ClientDataSetFeedsSerd.Value;
1547
          19: // Proline
1548
            Cumul := ClientDataSetFeedsProd.Value;
1549
          else
1550
            Cumul := 0;
1551
        end;
1552
      4: // Min?raux
1553
        case ComboBoxMinerals3.ItemIndex of
1554
          0: // Calcium
1555
            Cumul := ClientDataSetFeedsCa.Value;
1556
          1: // Phosphore
1557
            Cumul := ClientDataSetFeedsP.Value;
1558
          2: // Phosphore digestible
1559
            Cumul := ClientDataSetFeedsPd.Value;
1560
          else
1561
            Cumul := 0;
1562
        end;
1563
      else
1564
        Cumul := 0;
1565
    end;
1566
    if Cumul = 0
1567
    then // Division par z?ro
1568
      Cumul := 1;
1569
    ClientDataSetComposition.First;
1570
    Total := 0;
1571
    while not ClientDataSetComposition.Eof do
1572
    begin
1573
      if ClientDataSetCompositionUser.Value
1574
      then
1575
        ClientDataSetIngredients.Filter := Format('Id = %d and User', [ClientDataSetCompositionIngredient.Value])
1576
      else
1577
        ClientDataSetIngredients.Filter := Format('Id = %d and not User', [ClientDataSetCompositionIngredient.Value]);
1578
      ClientDataSetIngredients.Filtered := True;
1579
      IngredientName := StrTrunc(ClientDataSetIngredientsName.Value, 25);
1580
      Ratio := InputIncorporation(ClientDataSetCompositionLevel.Value, FormOptions.Incorporation);
1581
      if (FormOptions.Expression = 0)
1582
      and ((ComboBoxType3.ItemIndex <> 0) or (ComboBoxProximal3.ItemIndex > 1))
1583
      then // Conversion frais -> sec (mati?re s?che de la mati?re premi?re) - except? pour Composition et MS
1584
        Ratio := Ratio / InputProximal(ClientDataSetIngredientsMS.Value, 1, 1, FormOptions.Proximal);
1585
      RapMS := InputProximal(ClientDataSetCompositionMS.Value, 1, 1, FormOptions.Proximal);
1586
      if ((ComboBoxType3.ItemIndex <> 0) or (ComboBoxProximal3.ItemIndex > 1))
1587
      then // Conversion sec -> frais (mati?re s?che de la composition) - except? pour Composition et MS
1588
        Ratio := Ratio * RapMS;
1589
      case ComboBoxType3.ItemIndex of
1590
        0: // Analyse proximale
1591
          case ComboBoxProximal3.ItemIndex of
1592
            0: // Composition
1593
              Value := OutputProximal(Ratio, 1, 1, FormOptions.Proximal);
1594
            1: // MS
1595
              Value := ClientDataSetCompositionMS.Value * Ratio;
1596
            2: // MM
1597
              Value := ClientDataSetIngredientsMM.Value * Ratio;
1598
            3: // MAT
1599
              Value := ClientDataSetIngredientsMAT.Value * Ratio;
1600
            4: // MG
1601
              Value := ClientDataSetIngredientsMG.Value * Ratio;
1602
            5: // CB
1603
              Value := ClientDataSetIngredientsCB.Value * Ratio;
1604
            6: // NDF
1605
              Value := ClientDataSetIngredientsNDF.Value * Ratio;
1606
            7: // ADF
1607
              Value := ClientDataSetIngredientsADF.Value * Ratio;
1608
            8: // ADL
1609
              Value := ClientDataSetIngredientsADL.Value * Ratio;
1610
            9: // Amidon
1611
              Value := ClientDataSetIngredientsAmidon.Value * Ratio;
1612
            10: // Sucres
1613
              Value := ClientDataSetIngredientsSucres.Value * Ratio;
1614
            else
1615
              Value := 0;
1616
          end;
1617
        1: // Valeurs ?nerg?tiques
1618
          case ComboBoxEnergy3.ItemIndex of
1619
            0: // Energie brute
1620
              Value := ClientDataSetIngredientsEB.Value * Ratio;
1621
            1: // Energie digestible (porc croissance)
1622
              Value := ClientDataSetIngredientsEDc.Value * Ratio;
1623
            2: // Energie digestible (porc adulte)
1624
              Value := ClientDataSetIngredientsEDt.Value * Ratio;
1625
            3: // Energie m?tabolisable (porc croissance)
1626
              Value := ClientDataSetIngredientsEMc.Value * Ratio;
1627
            4: // Energie m?tabolisable (porc adulte)
1628
              Value := ClientDataSetIngredientsEMt.Value * Ratio;
1629
            5: // Energie nette (porc croissance)
1630
              Value := ClientDataSetIngredientsENc.Value * Ratio;
1631
            6: // Energie nette (porc adulte)
1632
              Value := ClientDataSetIngredientsENt.Value * Ratio;
1633
            else
1634
              Value := 0;
1635
          end;
1636
        2: // Acides amin?s totaux
1637
          case ComboBoxAA3.ItemIndex of
1638
            0: // Lysine
1639
              Value := ClientDataSetIngredientsLys.Value * Ratio;
1640
            1: // Thr?onine
1641
              Value := ClientDataSetIngredientsThr.Value * Ratio;
1642
            2: // M?thionine
1643
              Value := ClientDataSetIngredientsMet.Value * Ratio;
1644
            3: // Cyst?ine
1645
              Value := ClientDataSetIngredientsCys.Value * Ratio;
1646
            4: // M?thionine + Cyst?ine
1647
              Value := ClientDataSetIngredientsMetCys.Value * Ratio;
1648
            5: // Tryptophane
1649
              Value := ClientDataSetIngredientsTrp.Value * Ratio;
1650
            6: // Isoleucine
1651
              Value := ClientDataSetIngredientsIle.Value * Ratio;
1652
            7: // Valine
1653
              Value := ClientDataSetIngredientsVal.Value * Ratio;
1654
            8: // Leucine
1655
              Value := ClientDataSetIngredientsLeu.Value * Ratio;
1656
            9: // Ph?nylalanine
1657
              Value := ClientDataSetIngredientsPhe.Value * Ratio;
1658
            10: // Tyrosine
1659
              Value := ClientDataSetIngredientsTyr.Value * Ratio;
1660
            11: // Ph?nylalanine + Tyrosine
1661
              Value := ClientDataSetIngredientsPheTyr.Value * Ratio;
1662
            12: // Histidine
1663
              Value := ClientDataSetIngredientsHis.Value * Ratio;
1664
            13: // Arginine
1665
              Value := ClientDataSetIngredientsArg.Value * Ratio;
1666
            14: // Alanine
1667
              Value := ClientDataSetIngredientsAla.Value * Ratio;
1668
            15: // Aspartate
1669
              Value := ClientDataSetIngredientsAsp.Value * Ratio;
1670
            16: // Glutamate
1671
              Value := ClientDataSetIngredientsGlu.Value * Ratio;
1672
            17: // Glycine
1673
              Value := ClientDataSetIngredientsGly.Value * Ratio;
1674
            18: // S?rine
1675
              Value := ClientDataSetIngredientsSer.Value * Ratio;
1676
            19: // Proline
1677
              Value := ClientDataSetIngredientsPro.Value * Ratio;
1678
            else
1679
              Value := 0;
1680
          end;
1681
        3: // Acides amin?s digestibles
1682
          case ComboBoxAA3.ItemIndex of
1683
            0: // Lysine
1684
              Value := ClientDataSetIngredientsLysd.Value * Ratio;
1685
            1: // Thr?onine
1686
              Value := ClientDataSetIngredientsThrd.Value * Ratio;
1687
            2: // M?thionine
1688
              Value := ClientDataSetIngredientsMetd.Value * Ratio;
1689
            3: // Cyst?ine
1690
              Value := ClientDataSetIngredientsCysd.Value * Ratio;
1691
            4: // M?thionine + Cyst?ine
1692
              Value := ClientDataSetIngredientsMetCysd.Value * Ratio;
1693
            5: // Tryptophane
1694
              Value := ClientDataSetIngredientsTrpd.Value * Ratio;
1695
            6: // Isoleucine
1696
              Value := ClientDataSetIngredientsIled.Value * Ratio;
1697
            7: // Valine
1698
              Value := ClientDataSetIngredientsVald.Value * Ratio;
1699
            8: // Leucine
1700
              Value := ClientDataSetIngredientsLeud.Value * Ratio;
1701
            9: // Ph?nylalanine
1702
              Value := ClientDataSetIngredientsPhed.Value * Ratio;
1703
            10: // Tyrosine
1704
              Value := ClientDataSetIngredientsTyrd.Value * Ratio;
1705
            11: // Ph?nylalanine + Tyrosine
1706
              Value := ClientDataSetIngredientsPheTyrd.Value * Ratio;
1707
            12: // Histidine
1708
              Value := ClientDataSetIngredientsHisd.Value * Ratio;
1709
            13: // Arginine
1710
              Value := ClientDataSetIngredientsArgd.Value * Ratio;
1711
            14: // Alanine
1712
              Value := ClientDataSetIngredientsAlad.Value * Ratio;
1713
            15: // Aspartate
1714
              Value := ClientDataSetIngredientsAspd.Value * Ratio;
1715
            16: // Glutamate
1716
              Value := ClientDataSetIngredientsGlud.Value * Ratio;
1717
            17: // Glycine
1718
              Value := ClientDataSetIngredientsGlyd.Value * Ratio;
1719
            18: // S?rine
1720
              Value := ClientDataSetIngredientsSerd.Value * Ratio;
1721
            19: // Proline
1722
              Value := ClientDataSetIngredientsProd.Value * Ratio;
1723
            else
1724
              Value := 0;
1725
          end;
1726
        4: // Min?raux
1727
          case ComboBoxMinerals3.ItemIndex of
1728
            0: // Calcium
1729
              Value := ClientDataSetIngredientsCa.Value * Ratio;
1730
            1: // Phosphore
1731
              Value := ClientDataSetIngredientsP.Value * Ratio;
1732
            2: // Phosphore digestible
1733
              if ClientDataSetFeedsPresentation.Value = 0
1734
              then // Farine (dPphy)
1735
                Value := ClientDataSetIngredientsdPphy.Value / 100 * ClientDataSetIngredientsP.Value * Ratio
1736
              else // Granul?s (dP)
1737
                Value := ClientDataSetIngredientsdP.Value / 100 * ClientDataSetIngredientsP.Value * Ratio;
1738
            else
1739
              Value := 0;
1740
          end;
1741
        else
1742
          Value := 0;
1743
      end;
1744
      if (FormOptions.Expression = 1)
1745
      and ((ComboBoxType3.ItemIndex <> 0) or (ComboBoxProximal3.ItemIndex > 1))
1746
      then // Conversion frais -> sec (mati?re s?che du r?gime) - except? pour Composition et MS
1747
        Value := Value / InputProximal(ClientDataSetFeedsMS.Value, 1, 1, FormOptions.Proximal);
1748
      if Value > 0
1749
      then // Prendre en compte la valeur
1750
      begin
1751
        FeedBar := TBarSeries.Create(Chart3);
1752
        FeedBar.ParentChart := Chart3;
1753
        FeedBar.Title := Format('%s (%1.2f %%)', [IngredientName, Value / Cumul * 100]);
1754
        FeedBar.BarPen.Color := FeedBar.SeriesColor;
1755
        FeedBar.MultiBar := mbStacked100;
1756
        FeedBar.Marks.Visible := False;
1757
        Chart3.AddSeries(FeedBar);
1758
        FeedBar.AddBar(Value, '', clTeeColor);
1759
        Total := Total + Value;
1760
      end;
1761
      ClientDataSetComposition.Next;
1762
    end;
1763
    ClientDataSetIngredients.Filtered := False;
1764
    ClientDataSetIngredients.Filter := '';
1765
    // Cas particuliers
1766
    if (ComboBoxType3.ItemIndex = 1)
1767
    and ((ComboBoxEnergy3.ItemIndex = 1)
1768
      or (ComboBoxEnergy3.ItemIndex = 3)
1769
      or (ComboBoxEnergy3.ItemIndex = 5))
1770
    and (ClientDataSetFeedsBonusC.Value > 0)
1771
    then // Bonus ?nergie (porc croissance)
1772
    begin
1773
      case ComboBoxEnergy3.ItemIndex of
1774
        1: Value := ClientDataSetFeedsEDc.Value - Total;
1775
        3: Value := ClientDataSetFeedsEMc.Value - Total;
1776
        5: Value := ClientDataSetFeedsENc.Value - Total;
1777
        else Value := 0;
1778
      end;
1779
      FeedBar := TBarSeries.Create(Chart3);
1780
      FeedBar.ParentChart := Chart3;
1781
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Energy bonus'), Value / Cumul * 100]);
1782
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
1783
      FeedBar.MultiBar := mbStacked100;
1784
      FeedBar.Marks.Visible := False;
1785
      Chart3.AddSeries(FeedBar);
1786
      FeedBar.AddBar(Value, '', clTeeColor);
1787
      Total := Total + Value;
1788
    end;
1789
    if (ComboBoxType3.ItemIndex = 1)
1790
    and ((ComboBoxEnergy3.ItemIndex = 2)
1791
      or (ComboBoxEnergy3.ItemIndex = 4)
1792
      or (ComboBoxEnergy3.ItemIndex = 6))
1793
    and (ClientDataSetFeedsBonusT.Value > 0)
1794
    then // Bonus ?nergie (porc adulte)
1795
    begin
1796
      case ComboBoxEnergy3.ItemIndex of
1797
        2: Value := ClientDataSetFeedsEDt.Value - Total;
1798
        4: Value := ClientDataSetFeedsEMt.Value - Total;
1799
        6: Value := ClientDataSetFeedsENt.Value - Total;
1800
        else Value := 0;
1801
      end;
1802
      FeedBar := TBarSeries.Create(Chart3);
1803
      FeedBar.ParentChart := Chart3;
1804
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Energy bonus'), Value / Cumul * 100]);
1805
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
1806
      FeedBar.MultiBar := mbStacked100;
1807
      FeedBar.Marks.Visible := False;
1808
      Chart3.AddSeries(FeedBar);
1809
      FeedBar.AddBar(Value, '', clTeeColor);
1810
      Total := Total + Value;
1811
    end;
1812
    if (ComboBoxType3.ItemIndex = 0)
1813
    and (ComboBoxProximal3.ItemIndex = 0)
1814
    and not ClientDataSetFeedsPhytaseId.IsNull
1815
    and (ClientDataSetFeedsPhytaseLevel.Value > 0)
1816
    then // Phytase (taux d'incorporation)
1817
    begin
1818
      Ratio := InputIncorporation(ClientDataSetFeedsPhytaseLevel.Value, FormOptions.Incorporation);
1819
      Value := OutputProximal(Ratio, 1, 1, FormOptions.Proximal);
1820
      FeedBar := TBarSeries.Create(Chart3);
1821
      FeedBar.ParentChart := Chart3;
1822
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Phytase'), Value / Cumul * 100]);
1823
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
1824
      FeedBar.MultiBar := mbStacked100;
1825
      FeedBar.Marks.Visible := False;
1826
      Chart3.AddSeries(FeedBar);
1827
      FeedBar.AddBar(Value, '', clTeeColor);
1828
      Total := Total + Value;
1829
    end;
1830
    if (ComboBoxType3.ItemIndex = 4)
1831
    and (ComboBoxMinerals3.ItemIndex = 2)
1832
    and not ClientDataSetFeedsPhytaseId.IsNull
1833
    and (ClientDataSetFeedsPd.Value > Total)
1834
    then // Phytase (Phosphore digestible)
1835
    begin
1836
      Value := ClientDataSetFeedsPd.Value - Total;
1837
      FeedBar := TBarSeries.Create(Chart3);
1838
      FeedBar.ParentChart := Chart3;
1839
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Phytase'), Value / Cumul * 100]);
1840
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
1841
      FeedBar.MultiBar := mbStacked100;
1842
      FeedBar.Marks.Visible := False;
1843
      Chart3.AddSeries(FeedBar);
1844
      FeedBar.AddBar(Value, '', clTeeColor);
1845
      Total := Total + Value;
1846
    end;
1847
    // Total
1848
    case ComboBoxType3.ItemIndex of
1849
      0: // Analyse proximale
1850
        if (FormOptions.Expression = 0) or (ComboBoxProximal3.ItemIndex < 2)
1851
        then // sur frais
1852
          Chart3.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.ProximalDecimals, Total, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal]]))
1853
        else // sur mati?re s?che - except? pour Composition et MS
1854
          Chart3.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.ProximalDecimals, Total, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]));
1855
      1: // Valeurs ?nerg?tiques
1856
        if FormOptions.Expression = 0
1857
        then // sur frais
1858
          Chart3.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.EnergyDecimals, Total, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy]]))
1859
        else // sur mati?re s?che
1860
          Chart3.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.EnergyDecimals, Total, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]));
1861
      2, 3: // Acides amin?s
1862
        if FormOptions.Expression = 0
1863
        then // sur frais
1864
          Chart3.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.AADecimals, Total, FormOptions.ComboBoxAA.Items[FormOptions.AA]]))
1865
        else // sur mati?re s?che
1866
          Chart3.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.AADecimals, Total, FormOptions.ComboBoxAA.Items[FormOptions.AA], _('DM')]));
1867
      4: // Min?raux
1868
        if FormOptions.Expression = 0
1869
        then // sur frais
1870
          Chart3.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.MineralsDecimals, Total, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals]]))
1871
        else // sur mati?re s?che
1872
          Chart3.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.MineralsDecimals, Total, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], _('DM')]));
1873
    end;
1874
  end;
1875
end;
1876
1877
procedure TFormFeedCharts.ComboBoxOption4Change(Sender: TObject);
1878
var
1879
  IngredientName: String;
1880
  Cumul, Ratio, Total, Value: Double;
1881
  FeedBar: TBarSeries;
1882
begin
1883
//  while Chart4.SeriesCount > 0 do
1884
//    Chart4.Series[0].Free;
1885
  Chart4.FreeAllSeries(nil);
1886
  Chart4.SubTitle.Clear;
1887
  with DataModuleDeclaration do
1888
  begin
1889
    Chart4.AxisVisible := True;
1890
    Chart4.SubTitle.Text.Add(ComboBoxType4.Text);
1891
    case ComboBoxType4.ItemIndex of
1892
      0: // Analyse proximale
1893
        Chart4.SubTitle.Text.Add(ComboBoxProximal4.Text);
1894
      1: // Valeurs ?nerg?tiques
1895
        Chart4.SubTitle.Text.Add(ComboBoxEnergy4.Text);
1896
      2, 3: // Acides amin?s
1897
        Chart4.SubTitle.Text.Add(ComboBoxAA4.Text);
1898
      4: // Min?raux
1899
        Chart4.SubTitle.Text.Add(ComboBoxMinerals4.Text);
1900
    end;
1901
    case ComboBoxType4.ItemIndex of
1902
      0: // Analyse proximale
1903
        case ComboBoxProximal4.ItemIndex of
1904
          0: // Composition
1905
            Cumul := OutputIncorporation(1, FormOptions.Incorporation);
1906
          1: // MS
1907
            Cumul := ClientDataSetFeedsMS.Value;
1908
          2: // MM
1909
            Cumul := ClientDataSetFeedsMM.Value;
1910
          3: // MAT
1911
            Cumul := ClientDataSetFeedsMAT.Value;
1912
          4: // MG
1913
            Cumul := ClientDataSetFeedsMG.Value;
1914
          5: // CB
1915
            Cumul := ClientDataSetFeedsCB.Value;
1916
          6: // NDF
1917
            Cumul := ClientDataSetFeedsNDF.Value;
1918
          7: // ADF
1919
            Cumul := ClientDataSetFeedsADF.Value;
1920
          8: // ADL
1921
            Cumul := ClientDataSetFeedsADL.Value;
1922
          9: // Amidon
1923
            Cumul := ClientDataSetFeedsAmidon.Value;
1924
          10: // Sucres
1925
            Cumul := ClientDataSetFeedsSucres.Value;
1926
          else
1927
            Cumul := 0;
1928
        end;
1929
      1: // Valeurs ?nerg?tiques
1930
        case ComboBoxEnergy4.ItemIndex of
1931
          0: // Energie brute
1932
            Cumul := ClientDataSetFeedsEB.Value;
1933
          1: // Energie digestible (porc croissance)
1934
            Cumul := ClientDataSetFeedsEDc.Value;
1935
          2: // Energie digestible (porc adulte)
1936
            Cumul := ClientDataSetFeedsEDt.Value;
1937
          3: // Energie m?tabolisable (porc croissance)
1938
            Cumul := ClientDataSetFeedsEMc.Value;
1939
          4: // Energie m?tabolisable (porc adulte)
1940
            Cumul := ClientDataSetFeedsEMt.Value;
1941
          5: // Energie nette (porc croissance)
1942
            Cumul := ClientDataSetFeedsENc.Value;
1943
          6: // Energie nette (porc adulte)
1944
            Cumul := ClientDataSetFeedsENt.Value;
1945
          else
1946
            Cumul := 0;
1947
        end;
1948
      2: // Acides amin?s totaux
1949
        case ComboBoxAA4.ItemIndex of
1950
          0: // Lysine
1951
            Cumul := ClientDataSetFeedsLys.Value;
1952
          1: // Thr?onine
1953
            Cumul := ClientDataSetFeedsThr.Value;
1954
          2: // M?thionine
1955
            Cumul := ClientDataSetFeedsMet.Value;
1956
          3: // Cyst?ine
1957
            Cumul := ClientDataSetFeedsCys.Value;
1958
          4: // M?thionine + Cyst?ine
1959
            Cumul := ClientDataSetFeedsMetCys.Value;
1960
          5: // Tryptophane
1961
            Cumul := ClientDataSetFeedsTrp.Value;
1962
          6: // Isoleucine
1963
            Cumul := ClientDataSetFeedsIle.Value;
1964
          7: // Valine
1965
            Cumul := ClientDataSetFeedsVal.Value;
1966
          8: // Leucine
1967
            Cumul := ClientDataSetFeedsLeu.Value;
1968
          9: // Ph?nylalanine
1969
            Cumul := ClientDataSetFeedsPhe.Value;
1970
          10: // Tyrosine
1971
            Cumul := ClientDataSetFeedsTyr.Value;
1972
          11: // Ph?nylalanine + Tyrosine
1973
            Cumul := ClientDataSetFeedsPheTyr.Value;
1974
          12: // Histidine
1975
            Cumul := ClientDataSetFeedsHis.Value;
1976
          13: // Arginine
1977
            Cumul := ClientDataSetFeedsArg.Value;
1978
          14: // Alanine
1979
            Cumul := ClientDataSetFeedsAla.Value;
1980
          15: // Aspartate
1981
            Cumul := ClientDataSetFeedsAsp.Value;
1982
          16: // Glutamate
1983
            Cumul := ClientDataSetFeedsGlu.Value;
1984
          17: // Glycine
1985
            Cumul := ClientDataSetFeedsGly.Value;
1986
          18: // S?rine
1987
            Cumul := ClientDataSetFeedsSer.Value;
1988
          19: // Proline
1989
            Cumul := ClientDataSetFeedsPro.Value;
1990
          else
1991
            Cumul := 0;
1992
        end;
1993
      3: // Acides amin?s digestibles
1994
        case ComboBoxAA4.ItemIndex of
1995
          0: // Lysine
1996
            Cumul := ClientDataSetFeedsLysd.Value;
1997
          1: // Thr?onine
1998
            Cumul := ClientDataSetFeedsThrd.Value;
1999
          2: // M?thionine
2000
            Cumul := ClientDataSetFeedsMetd.Value;
2001
          3: // Cyst?ine
2002
            Cumul := ClientDataSetFeedsCysd.Value;
2003
          4: // M?thionine + Cyst?ine
2004
            Cumul := ClientDataSetFeedsMetCysd.Value;
2005
          5: // Tryptophane
2006
            Cumul := ClientDataSetFeedsTrpd.Value;
2007
          6: // Isoleucine
2008
            Cumul := ClientDataSetFeedsIled.Value;
2009
          7: // Valine
2010
            Cumul := ClientDataSetFeedsVald.Value;
2011
          8: // Leucine
2012
            Cumul := ClientDataSetFeedsLeud.Value;
2013
          9: // Ph?nylalanine
2014
            Cumul := ClientDataSetFeedsPhed.Value;
2015
          10: // Tyrosine
2016
            Cumul := ClientDataSetFeedsTyrd.Value;
2017
          11: // Ph?nylalanine + Tyrosine
2018
            Cumul := ClientDataSetFeedsPheTyrd.Value;
2019
          12: // Histidine
2020
            Cumul := ClientDataSetFeedsHisd.Value;
2021
          13: // Arginine
2022
            Cumul := ClientDataSetFeedsArgd.Value;
2023
          14: // Alanine
2024
            Cumul := ClientDataSetFeedsAlad.Value;
2025
          15: // Aspartate
2026
            Cumul := ClientDataSetFeedsAspd.Value;
2027
          16: // Glutamate
2028
            Cumul := ClientDataSetFeedsGlud.Value;
2029
          17: // Glycine
2030
            Cumul := ClientDataSetFeedsGlyd.Value;
2031
          18: // S?rine
2032
            Cumul := ClientDataSetFeedsSerd.Value;
2033
          19: // Proline
2034
            Cumul := ClientDataSetFeedsProd.Value;
2035
          else
2036
            Cumul := 0;
2037
        end;
2038
      4: // Min?raux
2039
        case ComboBoxMinerals4.ItemIndex of
2040
          0: // Calcium
2041
            Cumul := ClientDataSetFeedsCa.Value;
2042
          1: // Phosphore
2043
            Cumul := ClientDataSetFeedsP.Value;
2044
          2: // Phosphore digestible
2045
            Cumul := ClientDataSetFeedsPd.Value;
2046
          else
2047
            Cumul := 0;
2048
        end;
2049
      else
2050
        Cumul := 0;
2051
    end;
2052
    if Cumul = 0
2053
    then // Division par z?ro
2054
      Cumul := 1;
2055
    ClientDataSetComposition.First;
2056
    Total := 0;
2057
    while not ClientDataSetComposition.Eof do
2058
    begin
2059
      if ClientDataSetCompositionUser.Value
2060
      then
2061
        ClientDataSetIngredients.Filter := Format('Id = %d and User', [ClientDataSetCompositionIngredient.Value])
2062
      else
2063
        ClientDataSetIngredients.Filter := Format('Id = %d and not User', [ClientDataSetCompositionIngredient.Value]);
2064
      ClientDataSetIngredients.Filtered := True;
2065
      IngredientName := StrTrunc(ClientDataSetIngredientsName.Value, 25);
2066
      Ratio := InputIncorporation(ClientDataSetCompositionLevel.Value, FormOptions.Incorporation);
2067
      if (FormOptions.Expression = 0)
2068
      and ((ComboBoxType4.ItemIndex <> 0) or (ComboBoxProximal4.ItemIndex > 1))
2069
      then // Conversion frais -> sec (mati?re s?che de la mati?re premi?re) - except? pour Composition et MS
2070
        Ratio := Ratio / InputProximal(ClientDataSetIngredientsMS.Value, 1, 1, FormOptions.Proximal);
2071
      RapMS := InputProximal(ClientDataSetCompositionMS.Value, 1, 1, FormOptions.Proximal);
2072
      if ((ComboBoxType4.ItemIndex <> 0) or (ComboBoxProximal4.ItemIndex > 1))
2073
      then // Conversion sec -> frais (mati?re s?che de la composition) - except? pour Composition et MS
2074
        Ratio := Ratio * RapMS;
2075
      case ComboBoxType4.ItemIndex of
2076
        0: // Analyse proximale
2077
          case ComboBoxProximal4.ItemIndex of
2078
            0: // Composition
2079
              Value := OutputProximal(Ratio, 1, 1, FormOptions.Proximal);
2080
            1: // MS
2081
              Value := ClientDataSetCompositionMS.Value * Ratio;
2082
            2: // MM
2083
              Value := ClientDataSetIngredientsMM.Value * Ratio;
2084
            3: // MAT
2085
              Value := ClientDataSetIngredientsMAT.Value * Ratio;
2086
            4: // MG
2087
              Value := ClientDataSetIngredientsMG.Value * Ratio;
2088
            5: // CB
2089
              Value := ClientDataSetIngredientsCB.Value * Ratio;
2090
            6: // NDF
2091
              Value := ClientDataSetIngredientsNDF.Value * Ratio;
2092
            7: // ADF
2093
              Value := ClientDataSetIngredientsADF.Value * Ratio;
2094
            8: // ADL
2095
              Value := ClientDataSetIngredientsADL.Value * Ratio;
2096
            9: // Amidon
2097
              Value := ClientDataSetIngredientsAmidon.Value * Ratio;
2098
            10: // Sucres
2099
              Value := ClientDataSetIngredientsSucres.Value * Ratio;
2100
            else
2101
              Value := 0;
2102
          end;
2103
        1: // Valeurs ?nerg?tiques
2104
          case ComboBoxEnergy4.ItemIndex of
2105
            0: // Energie brute
2106
              Value := ClientDataSetIngredientsEB.Value * Ratio;
2107
            1: // Energie digestible (porc croissance)
2108
              Value := ClientDataSetIngredientsEDc.Value * Ratio;
2109
            2: // Energie digestible (porc adulte)
2110
              Value := ClientDataSetIngredientsEDt.Value * Ratio;
2111
            3: // Energie m?tabolisable (porc croissance)
2112
              Value := ClientDataSetIngredientsEMc.Value * Ratio;
2113
            4: // Energie m?tabolisable (porc adulte)
2114
              Value := ClientDataSetIngredientsEMt.Value * Ratio;
2115
            5: // Energie nette (porc croissance)
2116
              Value := ClientDataSetIngredientsENc.Value * Ratio;
2117
            6: // Energie nette (porc adulte)
2118
              Value := ClientDataSetIngredientsENt.Value * Ratio;
2119
            else
2120
              Value := 0;
2121
          end;
2122
        2: // Acides amin?s totaux
2123
          case ComboBoxAA4.ItemIndex of
2124
            0: // Lysine
2125
              Value := ClientDataSetIngredientsLys.Value * Ratio;
2126
            1: // Thr?onine
2127
              Value := ClientDataSetIngredientsThr.Value * Ratio;
2128
            2: // M?thionine
2129
              Value := ClientDataSetIngredientsMet.Value * Ratio;
2130
            3: // Cyst?ine
2131
              Value := ClientDataSetIngredientsCys.Value * Ratio;
2132
            4: // M?thionine + Cyst?ine
2133
              Value := ClientDataSetIngredientsMetCys.Value * Ratio;
2134
            5: // Tryptophane
2135
              Value := ClientDataSetIngredientsTrp.Value * Ratio;
2136
            6: // Isoleucine
2137
              Value := ClientDataSetIngredientsIle.Value * Ratio;
2138
            7: // Valine
2139
              Value := ClientDataSetIngredientsVal.Value * Ratio;
2140
            8: // Leucine
2141
              Value := ClientDataSetIngredientsLeu.Value * Ratio;
2142
            9: // Ph?nylalanine
2143
              Value := ClientDataSetIngredientsPhe.Value * Ratio;
2144
            10: // Tyrosine
2145
              Value := ClientDataSetIngredientsTyr.Value * Ratio;
2146
            11: // Ph?nylalanine + Tyrosine
2147
              Value := ClientDataSetIngredientsPheTyr.Value * Ratio;
2148
            12: // Histidine
2149
              Value := ClientDataSetIngredientsHis.Value * Ratio;
2150
            13: // Arginine
2151
              Value := ClientDataSetIngredientsArg.Value * Ratio;
2152
            14: // Alanine
2153
              Value := ClientDataSetIngredientsAla.Value * Ratio;
2154
            15: // Aspartate
2155
              Value := ClientDataSetIngredientsAsp.Value * Ratio;
2156
            16: // Glutamate
2157
              Value := ClientDataSetIngredientsGlu.Value * Ratio;
2158
            17: // Glycine
2159
              Value := ClientDataSetIngredientsGly.Value * Ratio;
2160
            18: // S?rine
2161
              Value := ClientDataSetIngredientsSer.Value * Ratio;
2162
            19: // Proline
2163
              Value := ClientDataSetIngredientsPro.Value * Ratio;
2164
            else
2165
              Value := 0;
2166
          end;
2167
        3: // Acides amin?s digestibles
2168
          case ComboBoxAA4.ItemIndex of
2169
            0: // Lysine
2170
              Value := ClientDataSetIngredientsLysd.Value * Ratio;
2171
            1: // Thr?onine
2172
              Value := ClientDataSetIngredientsThrd.Value * Ratio;
2173
            2: // M?thionine
2174
              Value := ClientDataSetIngredientsMetd.Value * Ratio;
2175
            3: // Cyst?ine
2176
              Value := ClientDataSetIngredientsCysd.Value * Ratio;
2177
            4: // M?thionine + Cyst?ine
2178
              Value := ClientDataSetIngredientsMetCysd.Value * Ratio;
2179
            5: // Tryptophane
2180
              Value := ClientDataSetIngredientsTrpd.Value * Ratio;
2181
            6: // Isoleucine
2182
              Value := ClientDataSetIngredientsIled.Value * Ratio;
2183
            7: // Valine
2184
              Value := ClientDataSetIngredientsVald.Value * Ratio;
2185
            8: // Leucine
2186
              Value := ClientDataSetIngredientsLeud.Value * Ratio;
2187
            9: // Ph?nylalanine
2188
              Value := ClientDataSetIngredientsPhed.Value * Ratio;
2189
            10: // Tyrosine
2190
              Value := ClientDataSetIngredientsTyrd.Value * Ratio;
2191
            11: // Ph?nylalanine + Tyrosine
2192
              Value := ClientDataSetIngredientsPheTyrd.Value * Ratio;
2193
            12: // Histidine
2194
              Value := ClientDataSetIngredientsHisd.Value * Ratio;
2195
            13: // Arginine
2196
              Value := ClientDataSetIngredientsArgd.Value * Ratio;
2197
            14: // Alanine
2198
              Value := ClientDataSetIngredientsAlad.Value * Ratio;
2199
            15: // Aspartate
2200
              Value := ClientDataSetIngredientsAspd.Value * Ratio;
2201
            16: // Glutamate
2202
              Value := ClientDataSetIngredientsGlud.Value * Ratio;
2203
            17: // Glycine
2204
              Value := ClientDataSetIngredientsGlyd.Value * Ratio;
2205
            18: // S?rine
2206
              Value := ClientDataSetIngredientsSerd.Value * Ratio;
2207
            19: // Proline
2208
              Value := ClientDataSetIngredientsProd.Value * Ratio;
2209
            else
2210
              Value := 0;
2211
          end;
2212
        4: // Min?raux
2213
          case ComboBoxMinerals4.ItemIndex of
2214
            0: // Calcium
2215
              Value := ClientDataSetIngredientsCa.Value * Ratio;
2216
            1: // Phosphore
2217
              Value := ClientDataSetIngredientsP.Value * Ratio;
2218
            2: // Phosphore digestible
2219
              if ClientDataSetFeedsPresentation.Value = 0
2220
              then // Farine (dPphy)
2221
                Value := ClientDataSetIngredientsdPphy.Value / 100 * ClientDataSetIngredientsP.Value * Ratio
2222
              else // Granul?s (dP)
2223
                Value := ClientDataSetIngredientsdP.Value / 100 * ClientDataSetIngredientsP.Value * Ratio;
2224
            else
2225
              Value := 0;
2226
          end;
2227
        else
2228
          Value := 0;
2229
      end;
2230
      if (FormOptions.Expression = 1)
2231
      and ((ComboBoxType4.ItemIndex <> 0) or (ComboBoxProximal4.ItemIndex > 1))
2232
      then // Conversion frais -> sec (mati?re s?che du r?gime) - except? pour Composition et MS
2233
        Value := Value / InputProximal(ClientDataSetFeedsMS.Value, 1, 1, FormOptions.Proximal);
2234
      if Value > 0
2235
      then // Prendre en compte la valeur
2236
      begin
2237
        FeedBar := TBarSeries.Create(Chart4);
2238
        FeedBar.ParentChart := Chart4;
2239
        FeedBar.Title := Format('%s (%1.2f %%)', [IngredientName, Value / Cumul * 100]);
2240
        FeedBar.BarPen.Color := FeedBar.SeriesColor;
2241
        FeedBar.MultiBar := mbStacked100;
2242
        FeedBar.Marks.Visible := False;
2243
        Chart4.AddSeries(FeedBar);
2244
        FeedBar.AddBar(Value, '', clTeeColor);
2245
        Total := Total + Value;
2246
      end;
2247
      ClientDataSetComposition.Next;
2248
    end;
2249
    ClientDataSetIngredients.Filtered := False;
2250
    ClientDataSetIngredients.Filter := '';
2251
    // Cas particuliers
2252
    if (ComboBoxType4.ItemIndex = 1)
2253
    and ((ComboBoxEnergy4.ItemIndex = 1)
2254
      or (ComboBoxEnergy4.ItemIndex = 3)
2255
      or (ComboBoxEnergy4.ItemIndex = 5))
2256
    and (ClientDataSetFeedsBonusC.Value > 0)
2257
    then // Bonus ?nergie (porc croissance)
2258
    begin
2259
      case ComboBoxEnergy4.ItemIndex of
2260
        1: Value := ClientDataSetFeedsEDc.Value - Total;
2261
        3: Value := ClientDataSetFeedsEMc.Value - Total;
2262
        5: Value := ClientDataSetFeedsENc.Value - Total;
2263
        else Value := 0;
2264
      end;
2265
      FeedBar := TBarSeries.Create(Chart4);
2266
      FeedBar.ParentChart := Chart4;
2267
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Energy bonus'), Value / Cumul * 100]);
2268
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
2269
      FeedBar.MultiBar := mbStacked100;
2270
      FeedBar.Marks.Visible := False;
2271
      Chart4.AddSeries(FeedBar);
2272
      FeedBar.AddBar(Value, '', clTeeColor);
2273
      Total := Total + Value;
2274
    end;
2275
    if (ComboBoxType4.ItemIndex = 1)
2276
    and ((ComboBoxEnergy4.ItemIndex = 2)
2277
      or (ComboBoxEnergy4.ItemIndex = 4)
2278
      or (ComboBoxEnergy4.ItemIndex = 6))
2279
    and (ClientDataSetFeedsBonusT.Value > 0)
2280
    then // Bonus ?nergie (porc adulte)
2281
    begin
2282
      case ComboBoxEnergy4.ItemIndex of
2283
        2: Value := ClientDataSetFeedsEDt.Value - Total;
2284
        4: Value := ClientDataSetFeedsEMt.Value - Total;
2285
        6: Value := ClientDataSetFeedsENt.Value - Total;
2286
        else Value := 0;
2287
      end;
2288
      FeedBar := TBarSeries.Create(Chart4);
2289
      FeedBar.ParentChart := Chart4;
2290
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Energy bonus'), Value / Cumul * 100]);
2291
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
2292
      FeedBar.MultiBar := mbStacked100;
2293
      FeedBar.Marks.Visible := False;
2294
      Chart4.AddSeries(FeedBar);
2295
      FeedBar.AddBar(Value, '', clTeeColor);
2296
      Total := Total + Value;
2297
    end;
2298
    if (ComboBoxType4.ItemIndex = 0)
2299
    and (ComboBoxProximal4.ItemIndex = 0)
2300
    and not ClientDataSetFeedsPhytaseId.IsNull
2301
    and (ClientDataSetFeedsPhytaseLevel.Value > 0)
2302
    then // Phytase (taux d'incorporation)
2303
    begin
2304
      Ratio := InputIncorporation(ClientDataSetFeedsPhytaseLevel.Value, FormOptions.Incorporation);
2305
      Value := OutputProximal(Ratio, 1, 1, FormOptions.Proximal);
2306
      FeedBar := TBarSeries.Create(Chart4);
2307
      FeedBar.ParentChart := Chart4;
2308
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Phytase'), Value / Cumul * 100]);
2309
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
2310
      FeedBar.MultiBar := mbStacked100;
2311
      FeedBar.Marks.Visible := False;
2312
      Chart4.AddSeries(FeedBar);
2313
      FeedBar.AddBar(Value, '', clTeeColor);
2314
      Total := Total + Value;
2315
    end;
2316
    if (ComboBoxType4.ItemIndex = 4)
2317
    and (ComboBoxMinerals4.ItemIndex = 2)
2318
    and not ClientDataSetFeedsPhytaseId.IsNull
2319
    and (ClientDataSetFeedsPd.Value > Total)
2320
    then // Phytase (Phosphore digestible)
2321
    begin
2322
      Value := ClientDataSetFeedsPd.Value - Total;
2323
      FeedBar := TBarSeries.Create(Chart4);
2324
      FeedBar.ParentChart := Chart4;
2325
      FeedBar.Title := Format('%s (%1.2f %%)', [_('Phytase'), Value / Cumul * 100]);
2326
      FeedBar.BarPen.Color := FeedBar.SeriesColor;
2327
      FeedBar.MultiBar := mbStacked100;
2328
      FeedBar.Marks.Visible := False;
2329
      Chart4.AddSeries(FeedBar);
2330
      FeedBar.AddBar(Value, '', clTeeColor);
2331
      Total := Total + Value;
2332
    end;
2333
    // Total
2334
    case ComboBoxType4.ItemIndex of
2335
      0: // Analyse proximale
2336
        if (FormOptions.Expression = 0) or (ComboBoxProximal4.ItemIndex < 2)
2337
        then // sur frais
2338
          Chart4.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.ProximalDecimals, Total, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal]]))
2339
        else // sur mati?re s?che - except? pour Composition et MS
2340
          Chart4.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.ProximalDecimals, Total, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]));
2341
      1: // Valeurs ?nerg?tiques
2342
        if FormOptions.Expression = 0
2343
        then // sur frais
2344
          Chart4.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.EnergyDecimals, Total, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy]]))
2345
        else // sur mati?re s?che
2346
          Chart4.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.EnergyDecimals, Total, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]));
2347
      2, 3: // Acides amin?s
2348
        if FormOptions.Expression = 0
2349
        then // sur frais
2350
          Chart4.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.AADecimals, Total, FormOptions.ComboBoxAA.Items[FormOptions.AA]]))
2351
        else // sur mati?re s?che
2352
          Chart4.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.AADecimals, Total, FormOptions.ComboBoxAA.Items[FormOptions.AA], _('DM')]));
2353
      4: // Min?raux
2354
        if FormOptions.Expression = 0
2355
        then // sur frais
2356
          Chart4.SubTitle.Text.Add(Format('%s %1.*f %s', [_('Total:'), FormOptions.MineralsDecimals, Total, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals]]))
2357
        else // sur mati?re s?che
2358
          Chart4.SubTitle.Text.Add(Format('%s %1.*f %s %s', [_('Total:'), FormOptions.MineralsDecimals, Total, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], _('DM')]));
2359
    end;
2360
  end;
2361
end;
2362
2363
procedure TFormFeedCharts.ComboBoxType0Change(Sender: TObject);
2364
begin
2365
  ComboBoxProximal0.Visible := False;
2366
  ComboBoxEnergy0.Visible := False;
2367
  ComboBoxAA0.Visible := False;
2368
  ComboBoxMinerals0.Visible := False;
2369
  case ComboBoxType0.ItemIndex of
2370
    0: // Analyse proximale
2371
      ComboBoxProximal0.Visible := True;
2372
    1: // Valeurs ?nerg?tiques
2373
      ComboBoxEnergy0.Visible := True;
2374
    2, 3: // Acides amin?s
2375
      ComboBoxAA0.Visible := True;
2376
    4: // Min?raux
2377
      ComboBoxMinerals0.Visible := True;
2378
  end;
2379
  ComboBoxOption0Change(nil);
2380
end;
2381
2382
procedure TFormFeedCharts.ComboBoxType1Change(Sender: TObject);
2383
begin
2384
  ComboBoxProximal1.Visible := False;
2385
  ComboBoxEnergy1.Visible := False;
2386
  ComboBoxAA1.Visible := False;
2387
  ComboBoxMinerals1.Visible := False;
2388
  case ComboBoxType1.ItemIndex of
2389
    0: // Analyse proximale
2390
      ComboBoxProximal1.Visible := True;
2391
    1: // Valeurs ?nerg?tiques
2392
      ComboBoxEnergy1.Visible := True;
2393
    2, 3: // Acides amin?s
2394
      ComboBoxAA1.Visible := True;
2395
    4: // Min?raux
2396
      ComboBoxMinerals1.Visible := True;
2397
  end;
2398
  ComboBoxOption1Change(nil);
2399
end;
2400
2401
procedure TFormFeedCharts.ComboBoxType2Change(Sender: TObject);
2402
begin
2403
  ComboBoxProximal2.Visible := False;
2404
  ComboBoxEnergy2.Visible := False;
2405
  ComboBoxAA2.Visible := False;
2406
  ComboBoxMinerals2.Visible := False;
2407
  case ComboBoxType2.ItemIndex of
2408
    0: // Analyse proximale
2409
      ComboBoxProximal2.Visible := True;
2410
    1: // Valeurs ?nerg?tiques
2411
      ComboBoxEnergy2.Visible := True;
2412
    2, 3: // Acides amin?s
2413
      ComboBoxAA2.Visible := True;
2414
    4: // Min?raux
2415
      ComboBoxMinerals2.Visible := True;
2416
  end;
2417
  ComboBoxOption2Change(nil);
2418
end;
2419
2420
procedure TFormFeedCharts.ComboBoxType3Change(Sender: TObject);
2421
begin
2422
  ComboBoxProximal3.Visible := False;
2423
  ComboBoxEnergy3.Visible := False;
2424
  ComboBoxAA3.Visible := False;
2425
  ComboBoxMinerals3.Visible := False;
2426
  case ComboBoxType3.ItemIndex of
2427
    0: // Analyse proximale
2428
      ComboBoxProximal3.Visible := True;
2429
    1: // Valeurs ?nerg?tiques
2430
      ComboBoxEnergy3.Visible := True;
2431
    2, 3: // Acides amin?s
2432
      ComboBoxAA3.Visible := True;
2433
    4: // Min?raux
2434
      ComboBoxMinerals3.Visible := True;
2435
  end;
2436
  ComboBoxOption3Change(nil);
2437
end;
2438
2439
procedure TFormFeedCharts.ComboBoxType4Change(Sender: TObject);
2440
begin
2441
  ComboBoxProximal4.Visible := False;
2442
  ComboBoxEnergy4.Visible := False;
2443
  ComboBoxAA4.Visible := False;
2444
  ComboBoxMinerals4.Visible := False;
2445
  case ComboBoxType4.ItemIndex of
2446
    0: // Analyse proximale
2447
      ComboBoxProximal4.Visible := True;
2448
    1: // Valeurs ?nerg?tiques
2449
      ComboBoxEnergy4.Visible := True;
2450
    2, 3: // Acides amin?s
2451
      ComboBoxAA4.Visible := True;
2452
    4: // Min?raux
2453
      ComboBoxMinerals4.Visible := True;
2454
  end;
2455
  ComboBoxOption4Change(nil);
2456
end;
2457
2458
procedure TFormFeedCharts.FormCreate(Sender: TObject);
2459
begin
2460
  if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
2461
  then
2462
  begin
2463
    Font.Name := 'Arial Unicode MS';
2464
    SetChartFont(Chart0, 'Arial Unicode MS');
2465
    SeriesPie.Marks.Font.Name := 'Arial Unicode MS';
2466
//    SeriesPie.OtherSlice.Legend.Font.Name := 'Arial Unicode MS';
2467
    SetChartFont(Chart1, 'Arial Unicode MS');
2468
    SetChartFont(Chart2, 'Arial Unicode MS');
2469
    SetChartFont(Chart3, 'Arial Unicode MS');
2470
    SetChartFont(Chart4, 'Arial Unicode MS');
2471
  end;
2472
//  PanelButtons.Font.Size := PanelButtons.Font.Size + 2;
2473
  PanelButtons.Font.Style := [fsBold];
2474
  TranslateComponent(Self);
2475
  // S?lection des ?l?ments par d?faut apr?s traduction des listes
2476
  ComboBoxType0.ItemIndex := 0;
2477
  ComboBoxProximal0.ItemIndex := 0;
2478
  ComboBoxEnergy0.ItemIndex := 0;
2479
  ComboBoxAA0.ItemIndex := 0;
2480
  ComboBoxMinerals0.ItemIndex := 0;
2481
  Chart0.SubTitle.Clear;
2482
  Chart1.Title.Clear;
2483
  Chart1.SubTitle.Clear;
2484
  Chart2.Title.Clear;
2485
  Chart2.SubTitle.Clear;
2486
  Chart3.Title.Clear;
2487
  Chart3.SubTitle.Clear;
2488
  Chart4.Title.Clear;
2489
  Chart4.SubTitle.Clear;
2490
  with DataModuleDeclaration do
2491
  begin
2492
    ClientDataSetComposition.Filter := Format('Feed = %d', [ClientDataSetFeedsId.Value]);
2493
    ClientDataSetComposition.Filtered := True;
2494
    Chart0.Title.Caption := ClientDataSetFeedsName.Value;
2495
    Chart1.Title.Caption := ClientDataSetFeedsName.Value;
2496
    Chart2.Title.Caption := ClientDataSetFeedsName.Value;
2497
    Chart3.Title.Caption := ClientDataSetFeedsName.Value;
2498
    Chart4.Title.Caption := ClientDataSetFeedsName.Value;
2499
  end;
2500
end;
2501
2502
procedure TFormFeedCharts.FormDestroy(Sender: TObject);
2503
begin
2504
  with DataModuleDeclaration do
2505
  begin
2506
    ClientDataSetComposition.Filtered := False;
2507
    ClientDataSetComposition.Filter := '';
2508
  end;
2509
end;
2510
2511
procedure TFormFeedCharts.FormShow(Sender: TObject);
2512
begin
2513
  ComboBoxOption0Change(nil);
2514
end;
2515
2516
procedure TFormFeedCharts.FormResize(Sender: TObject);
2517
var
2518
  W, H: Integer;
2519
begin
2520
  W := TabSheetChartsComparison.Width div 2;
2521
  H := TabSheetChartsComparison.Height div 2;
2522
  GroupBoxChart1.SetBounds(0, 0, W, H);
2523
  GroupBoxChart2.SetBounds(W, 0, W, H);
2524
  GroupBoxChart3.SetBounds(0, H, W, H);
2525
  GroupBoxChart4.SetBounds(W, H, W, H);
2526
end;
2527
2528
procedure TFormFeedCharts.SpeedButton2D3D0Click(Sender: TObject);
2529
begin
2530
  Chart0.View3D := not Chart0.View3D;
2531
  if Chart0.View3D
2532
  then
2533
    SpeedButton2D3D0.Caption := _('2D')
2534
  else
2535
    SpeedButton2D3D0.Caption := _('3D');
2536
end;
2537
2538
procedure TFormFeedCharts.SpeedButton2D3D1Click(Sender: TObject);
2539
begin
2540
  Chart1.View3D := not Chart1.View3D;
2541
  if Chart1.View3D
2542
  then
2543
    SpeedButton2D3D1.Caption := _('2D')
2544
  else
2545
    SpeedButton2D3D1.Caption := _('3D');
2546
end;
2547
2548
procedure TFormFeedCharts.SpeedButton2D3D2Click(Sender: TObject);
2549
begin
2550
  Chart2.View3D := not Chart2.View3D;
2551
  if Chart2.View3D
2552
  then
2553
    SpeedButton2D3D2.Caption := _('2D')
2554
  else
2555
    SpeedButton2D3D2.Caption := _('3D');
2556
end;
2557
2558
procedure TFormFeedCharts.SpeedButton2D3D3Click(Sender: TObject);
2559
begin
2560
  Chart3.View3D := not Chart3.View3D;
2561
  if Chart3.View3D
2562
  then
2563
    SpeedButton2D3D3.Caption := _('2D')
2564
  else
2565
    SpeedButton2D3D3.Caption := _('3D');
2566
end;
2567
2568
procedure TFormFeedCharts.SpeedButton2D3D4Click(Sender: TObject);
2569
begin
2570
  Chart4.View3D := not Chart4.View3D;
2571
  if Chart4.View3D
2572
  then
2573
    SpeedButton2D3D4.Caption := _('2D')
2574
  else
2575
    SpeedButton2D3D4.Caption := _('3D');
2576
end;
2577
2578
procedure TFormFeedCharts.SpeedButtonPrint0Click(Sender: TObject);
2579
begin
2580
  FormChartHReport := TFormChartHReport.Create(nil);
2581
  try
2582
    FormChartHReport.QRChart1.Chart.View3D := Chart0.View3D;
2583
    FormChartHReport.QRChart1.Chart.Title.Assign(Chart0.Title);
2584
    FormChartHReport.QRChart1.Chart.SubTitle.Assign(Chart0.SubTitle);
2585
    FormChartHReport.QRChart1.Chart.Legend.Visible := False;
2586
    SeriesPie.OtherSlice.Style := poNone;
2587
    CloneChartSeries(SeriesPie).ParentChart := FormChartHReport.QRChart1.Chart;
2588
    if Chart0.View3D
2589
    then
2590
    begin
2591
      FormChartHReport.QRChart1.Chart.FreeAllSeries(nil);
2592
      CloneChartSeries(SeriesPie).ParentChart := FormChartHReport.QRChart1.Chart;
2593
    end;
2594
    SeriesPie.OtherSlice.Style := poBelowPercent;
2595
    TPieSeries(FormChartHReport.QRChart1.Chart[0]).OtherSlice.Style := poBelowPercent;
2596
    FormChartHReport.QuickRepChart.PrinterSetup;
2597
    if FormChartHReport.QuickRepChart.Tag = 0
2598
    then
2599
      FormChartHReport.QuickRepChart.Print;
2600
  finally
2601
    FormChartHReport.Release;
2602
  end;
2603
end;
2604
2605
procedure TFormFeedCharts.SpeedButtonPrint1Click(Sender: TObject);
2606
var
2607
  i: Integer;
2608
begin
2609
  FormChartHReport := TFormChartHReport.Create(nil);
2610
  try
2611
    FormChartHReport.QRChart1.Chart.View3D := Chart1.View3D;
2612
    FormChartHReport.QRChart1.Chart.Title.Assign(Chart1.Title);
2613
    FormChartHReport.QRChart1.Chart.SubTitle.Assign(Chart1.SubTitle);
2614
    FormChartHReport.QRChart1.Chart.BottomAxis.Labels := False;
2615
    for i := 0 to Chart1.SeriesCount - 1 do
2616
      CloneChartSeries(Chart1[i]).ParentChart := FormChartHReport.QRChart1.Chart;
2617
    FormChartHReport.QuickRepChart.PrinterSetup;
2618
    if FormChartHReport.QuickRepChart.Tag = 0
2619
    then
2620
      FormChartHReport.QuickRepChart.Print;
2621
  finally
2622
    FormChartHReport.Release;
2623
  end;
2624
end;
2625
2626
procedure TFormFeedCharts.SpeedButtonPrint2Click(Sender: TObject);
2627
var
2628
  i: Integer;
2629
begin
2630
  FormChartHReport := TFormChartHReport.Create(nil);
2631
  try
2632
    FormChartHReport.QRChart1.Chart.View3D := Chart2.View3D;
2633
    FormChartHReport.QRChart1.Chart.Title.Assign(Chart2.Title);
2634
    FormChartHReport.QRChart1.Chart.SubTitle.Assign(Chart2.SubTitle);
2635
    FormChartHReport.QRChart1.Chart.BottomAxis.Labels := False;
2636
    for i := 0 to Chart2.SeriesCount - 1 do
2637
      CloneChartSeries(Chart2[i]).ParentChart := FormChartHReport.QRChart1.Chart;
2638
    FormChartHReport.QuickRepChart.PrinterSetup;
2639
    if FormChartHReport.QuickRepChart.Tag = 0
2640
    then
2641
      FormChartHReport.QuickRepChart.Print;
2642
  finally
2643
    FormChartHReport.Release;
2644
  end;
2645
end;
2646
2647
procedure TFormFeedCharts.SpeedButtonPrint3Click(Sender: TObject);
2648
var
2649
  i: Integer;
2650
begin
2651
  FormChartHReport := TFormChartHReport.Create(nil);
2652
  try
2653
    FormChartHReport.QRChart1.Chart.View3D := Chart3.View3D;
2654
    FormChartHReport.QRChart1.Chart.Title.Assign(Chart3.Title);
2655
    FormChartHReport.QRChart1.Chart.SubTitle.Assign(Chart3.SubTitle);
2656
    FormChartHReport.QRChart1.Chart.BottomAxis.Labels := False;
2657
    for i := 0 to Chart3.SeriesCount - 1 do
2658
      CloneChartSeries(Chart3[i]).ParentChart := FormChartHReport.QRChart1.Chart;
2659
    FormChartHReport.QuickRepChart.PrinterSetup;
2660
    if FormChartHReport.QuickRepChart.Tag = 0
2661
    then
2662
      FormChartHReport.QuickRepChart.Print;
2663
  finally
2664
    FormChartHReport.Release;
2665
  end;
2666
end;
2667
2668
procedure TFormFeedCharts.SpeedButtonPrint4Click(Sender: TObject);
2669
var
2670
  i: Integer;
2671
begin
2672
  FormChartHReport := TFormChartHReport.Create(nil);
2673
  try
2674
    FormChartHReport.QRChart1.Chart.View3D := Chart4.View3D;
2675
    FormChartHReport.QRChart1.Chart.Title.Assign(Chart4.Title);
2676
    FormChartHReport.QRChart1.Chart.SubTitle.Assign(Chart4.SubTitle);
2677
    FormChartHReport.QRChart1.Chart.BottomAxis.Labels := False;
2678
    for i := 0 to Chart4.SeriesCount - 1 do
2679
      CloneChartSeries(Chart4[i]).ParentChart := FormChartHReport.QRChart1.Chart;
2680
    FormChartHReport.QuickRepChart.PrinterSetup;
2681
    if FormChartHReport.QuickRepChart.Tag = 0
2682
    then
2683
      FormChartHReport.QuickRepChart.Print;
2684
  finally
2685
    FormChartHReport.Release;
2686
  end;
2687
end;
2688
2689
procedure TFormFeedCharts.WMSysCommand(var Message: TWMSysCommand);
2690
begin
2691
  if Message.CmdType = SC_MINIMIZE
2692
  then
2693
    Application.Minimize
2694
  else
2695
    inherited;
2696
end;
2697
2698
end.