Statistiques
| Révision:

root / UnitDeclaration.pas @ 1

Historique | Voir | Annoter | Télécharger (204,188 ko)

1 1 avalancogn
unit UnitDeclaration;
2
3
interface
4
5
uses
6
  SysUtils, Classes, DB, DBTables, DbClient, SQLiteTable3, Forms, Windows,
7
  Dialogs, Variants, Math, MidasLib, LbClass, LbCipher, gnugettext;
8
9
const
10
  CALORIE = 4.184; // Conversion J -> cal
11
  NDF_ADF = 3.0;
12
  NDF_CB = 3.5;
13
  CoefMAT = 14.73 * 100 * CALORIE / 1000;
14
  CoefMG = 52.4 * 100 * CALORIE / 1000;
15
  CoefMM = -44.6 * 100 * CALORIE / 1000;
16
  dLys = 0.770;
17
  dThr = 0.760;
18
  dMet = 0.846;
19
  dCys = 0.733;
20
  dMetCys = 0.788;
21
  dTrp = 0.772;
22
  dIle = 0.807;
23
  dVal = 0.777;
24
  dLeu = 0.833;
25
  dPhe = 0.842;
26
  dTyr = 0.855;
27
  dPheTyr = 0.847;
28
  dHis = 0.841;
29
  dArg = 0.887;
30
  dAla = 0.773;
31
  dAsp = 0.791;
32
  dGlu = 0.861;
33
  dGly = 0.718;
34
  dSer = 0.807;
35
  dPro = 0.787;
36
37
type
38
  TDataModuleDeclaration = class(TDataModule)
39
    ClientDataSetClasses: TClientDataSet;
40
    ClientDataSetClassesId: TIntegerField;
41
    ClientDataSetClassesName: TWideStringField;
42
    ClientDataSetInraAfz: TClientDataSet;
43
    ClientDataSetInraAfzId: TAutoIncField;
44
    ClientDataSetInraAfzName: TStringField;
45
    ClientDataSetInraAfzSource: TStringField;
46
    ClientDataSetInraAfzClass: TIntegerField;
47
    ClientDataSetInraAfzMS: TFloatField;
48
    ClientDataSetInraAfzMM: TFloatField;
49
    ClientDataSetInraAfzMAT: TFloatField;
50
    ClientDataSetInraAfzMG: TFloatField;
51
    ClientDataSetInraAfzCB: TFloatField;
52
    ClientDataSetInraAfzCoefCB: TFloatField;
53
    ClientDataSetInraAfzNDF: TFloatField;
54
    ClientDataSetInraAfzCoefNDF: TFloatField;
55
    ClientDataSetInraAfzADF: TFloatField;
56
    ClientDataSetInraAfzCoefADF: TFloatField;
57
    ClientDataSetInraAfzADL: TFloatField;
58
    ClientDataSetInraAfzAmidon: TFloatField;
59
    ClientDataSetInraAfzSucres: TFloatField;
60
    ClientDataSetInraAfzEB: TFloatField;
61
    ClientDataSetInraAfzdEc: TFloatField;
62
    ClientDataSetInraAfzEMc_EDc: TFloatField;
63
    ClientDataSetInraAfzENc_EMc: TFloatField;
64
    ClientDataSetInraAfzEMt_EDt: TFloatField;
65
    ClientDataSetInraAfzENt_EMt: TFloatField;
66
    ClientDataSetInraAfzEDt_EDc: TFloatField;
67
    ClientDataSetInraAfza: TFloatField;
68
    ClientDataSetInraAfzb: TFloatField;
69
    ClientDataSetInraAfzdNc: TFloatField;
70
    ClientDataSetInraAfzdNt: TFloatField;
71
    ClientDataSetInraAfzLys: TFloatField;
72
    ClientDataSetInraAfzThr: TFloatField;
73
    ClientDataSetInraAfzMet: TFloatField;
74
    ClientDataSetInraAfzCys: TFloatField;
75
    ClientDataSetInraAfzMetCys: TFloatField;
76
    ClientDataSetInraAfzTrp: TFloatField;
77
    ClientDataSetInraAfzIle: TFloatField;
78
    ClientDataSetInraAfzVal: TFloatField;
79
    ClientDataSetInraAfzLeu: TFloatField;
80
    ClientDataSetInraAfzPhe: TFloatField;
81
    ClientDataSetInraAfzTyr: TFloatField;
82
    ClientDataSetInraAfzPheTyr: TFloatField;
83
    ClientDataSetInraAfzHis: TFloatField;
84
    ClientDataSetInraAfzArg: TFloatField;
85
    ClientDataSetInraAfzAla: TFloatField;
86
    ClientDataSetInraAfzAsp: TFloatField;
87
    ClientDataSetInraAfzGlu: TFloatField;
88
    ClientDataSetInraAfzGly: TFloatField;
89
    ClientDataSetInraAfzSer: TFloatField;
90
    ClientDataSetInraAfzPro: TFloatField;
91
    ClientDataSetInraAfzdLys: TFloatField;
92
    ClientDataSetInraAfzdThr: TFloatField;
93
    ClientDataSetInraAfzdMet: TFloatField;
94
    ClientDataSetInraAfzdCys: TFloatField;
95
    ClientDataSetInraAfzdMetCys: TFloatField;
96
    ClientDataSetInraAfzdTrp: TFloatField;
97
    ClientDataSetInraAfzdIle: TFloatField;
98
    ClientDataSetInraAfzdVal: TFloatField;
99
    ClientDataSetInraAfzdLeu: TFloatField;
100
    ClientDataSetInraAfzdPhe: TFloatField;
101
    ClientDataSetInraAfzdTyr: TFloatField;
102
    ClientDataSetInraAfzdPheTyr: TFloatField;
103
    ClientDataSetInraAfzdHis: TFloatField;
104
    ClientDataSetInraAfzdArg: TFloatField;
105
    ClientDataSetInraAfzdAla: TFloatField;
106
    ClientDataSetInraAfzdAsp: TFloatField;
107
    ClientDataSetInraAfzdGlu: TFloatField;
108
    ClientDataSetInraAfzdGly: TFloatField;
109
    ClientDataSetInraAfzdSer: TFloatField;
110
    ClientDataSetInraAfzdPro: TFloatField;
111
    ClientDataSetInraAfzCa: TFloatField;
112
    ClientDataSetInraAfzP: TFloatField;
113
    ClientDataSetInraAfzdP: TFloatField;
114
    ClientDataSetInraAfzdPphy: TFloatField;
115
    DataSourceInraAfz: TDataSource;
116
    ClientDataSetIngredients: TClientDataSet;
117
    ClientDataSetIngredientsId: TIntegerField;
118
    ClientDataSetIngredientsName: TWideStringField;
119
    ClientDataSetIngredientsDefinition: TWideStringField;
120
    ClientDataSetIngredientsClass: TIntegerField;
121
    ClientDataSetIngredientsClassName: TWideStringField;
122
    ClientDataSetIngredientsUser: TBooleanField;
123
    ClientDataSetIngredientsModel: TIntegerField;
124
    ClientDataSetIngredientsSource: TWideStringField;
125
    ClientDataSetIngredientsMS: TFloatField;
126
    ClientDataSetIngredientsMS2: TFloatField;
127
    ClientDataSetIngredientsMM: TFloatField;
128
    ClientDataSetIngredientsMAT: TFloatField;
129
    ClientDataSetIngredientsMG: TFloatField;
130
    ClientDataSetIngredientsCB: TFloatField;
131
    ClientDataSetIngredientsNDF: TFloatField;
132
    ClientDataSetIngredientsADF: TFloatField;
133
    ClientDataSetIngredientsADL: TFloatField;
134
    ClientDataSetIngredientsAmidon: TFloatField;
135
    ClientDataSetIngredientsSucres: TFloatField;
136
    ClientDataSetIngredientsEB: TFloatField;
137
    ClientDataSetIngredientsBonus: TFloatField;
138
    ClientDataSetIngredientsdEc: TFloatField;
139
    ClientDataSetIngredientsEDc: TFloatField;
140
    ClientDataSetIngredientsEMc_EDc: TFloatField;
141
    ClientDataSetIngredientsEMc: TFloatField;
142
    ClientDataSetIngredientsENc_EMc: TFloatField;
143
    ClientDataSetIngredientsENc: TFloatField;
144
    ClientDataSetIngredientsdEt: TFloatField;
145
    ClientDataSetIngredientsEDt: TFloatField;
146
    ClientDataSetIngredientsEMt_EDt: TFloatField;
147
    ClientDataSetIngredientsEMt: TFloatField;
148
    ClientDataSetIngredientsENt_EMt: TFloatField;
149
    ClientDataSetIngredientsENt: TFloatField;
150
    ClientDataSetIngredientsEDt_EDc: TFloatField;
151
    ClientDataSetIngredientsEMt_EMc: TFloatField;
152
    ClientDataSetIngredientsENt_ENc: TFloatField;
153
    ClientDataSetIngredientsdNc: TFloatField;
154
    ClientDataSetIngredientsdNt: TFloatField;
155
    ClientDataSetIngredientsLys: TFloatField;
156
    ClientDataSetIngredientsThr: TFloatField;
157
    ClientDataSetIngredientsMet: TFloatField;
158
    ClientDataSetIngredientsCys: TFloatField;
159
    ClientDataSetIngredientsMetCys: TFloatField;
160
    ClientDataSetIngredientsTrp: TFloatField;
161
    ClientDataSetIngredientsIle: TFloatField;
162
    ClientDataSetIngredientsVal: TFloatField;
163
    ClientDataSetIngredientsLeu: TFloatField;
164
    ClientDataSetIngredientsPhe: TFloatField;
165
    ClientDataSetIngredientsTyr: TFloatField;
166
    ClientDataSetIngredientsPheTyr: TFloatField;
167
    ClientDataSetIngredientsHis: TFloatField;
168
    ClientDataSetIngredientsArg: TFloatField;
169
    ClientDataSetIngredientsAla: TFloatField;
170
    ClientDataSetIngredientsAsp: TFloatField;
171
    ClientDataSetIngredientsGlu: TFloatField;
172
    ClientDataSetIngredientsGly: TFloatField;
173
    ClientDataSetIngredientsSer: TFloatField;
174
    ClientDataSetIngredientsPro: TFloatField;
175
    ClientDataSetIngredientsLys_MAT: TFloatField;
176
    ClientDataSetIngredientsThr_MAT: TFloatField;
177
    ClientDataSetIngredientsMet_MAT: TFloatField;
178
    ClientDataSetIngredientsCys_MAT: TFloatField;
179
    ClientDataSetIngredientsMetCys_MAT: TFloatField;
180
    ClientDataSetIngredientsTrp_MAT: TFloatField;
181
    ClientDataSetIngredientsIle_MAT: TFloatField;
182
    ClientDataSetIngredientsVal_MAT: TFloatField;
183
    ClientDataSetIngredientsLeu_MAT: TFloatField;
184
    ClientDataSetIngredientsPhe_MAT: TFloatField;
185
    ClientDataSetIngredientsTyr_MAT: TFloatField;
186
    ClientDataSetIngredientsPheTyr_MAT: TFloatField;
187
    ClientDataSetIngredientsHis_MAT: TFloatField;
188
    ClientDataSetIngredientsArg_MAT: TFloatField;
189
    ClientDataSetIngredientsAla_MAT: TFloatField;
190
    ClientDataSetIngredientsAsp_MAT: TFloatField;
191
    ClientDataSetIngredientsGlu_MAT: TFloatField;
192
    ClientDataSetIngredientsGly_MAT: TFloatField;
193
    ClientDataSetIngredientsSer_MAT: TFloatField;
194
    ClientDataSetIngredientsPro_MAT: TFloatField;
195
    ClientDataSetIngredientsdLys: TFloatField;
196
    ClientDataSetIngredientsdThr: TFloatField;
197
    ClientDataSetIngredientsdMet: TFloatField;
198
    ClientDataSetIngredientsdCys: TFloatField;
199
    ClientDataSetIngredientsdMetCys: TFloatField;
200
    ClientDataSetIngredientsdTrp: TFloatField;
201
    ClientDataSetIngredientsdIle: TFloatField;
202
    ClientDataSetIngredientsdVal: TFloatField;
203
    ClientDataSetIngredientsdLeu: TFloatField;
204
    ClientDataSetIngredientsdPhe: TFloatField;
205
    ClientDataSetIngredientsdTyr: TFloatField;
206
    ClientDataSetIngredientsdPheTyr: TFloatField;
207
    ClientDataSetIngredientsdHis: TFloatField;
208
    ClientDataSetIngredientsdArg: TFloatField;
209
    ClientDataSetIngredientsdAla: TFloatField;
210
    ClientDataSetIngredientsdAsp: TFloatField;
211
    ClientDataSetIngredientsdGlu: TFloatField;
212
    ClientDataSetIngredientsdGly: TFloatField;
213
    ClientDataSetIngredientsdSer: TFloatField;
214
    ClientDataSetIngredientsdPro: TFloatField;
215
    ClientDataSetIngredientsLysd: TFloatField;
216
    ClientDataSetIngredientsThrd: TFloatField;
217
    ClientDataSetIngredientsMetd: TFloatField;
218
    ClientDataSetIngredientsCysd: TFloatField;
219
    ClientDataSetIngredientsMetCysd: TFloatField;
220
    ClientDataSetIngredientsTrpd: TFloatField;
221
    ClientDataSetIngredientsIled: TFloatField;
222
    ClientDataSetIngredientsVald: TFloatField;
223
    ClientDataSetIngredientsLeud: TFloatField;
224
    ClientDataSetIngredientsPhed: TFloatField;
225
    ClientDataSetIngredientsTyrd: TFloatField;
226
    ClientDataSetIngredientsPheTyrd: TFloatField;
227
    ClientDataSetIngredientsHisd: TFloatField;
228
    ClientDataSetIngredientsArgd: TFloatField;
229
    ClientDataSetIngredientsAlad: TFloatField;
230
    ClientDataSetIngredientsAspd: TFloatField;
231
    ClientDataSetIngredientsGlud: TFloatField;
232
    ClientDataSetIngredientsGlyd: TFloatField;
233
    ClientDataSetIngredientsSerd: TFloatField;
234
    ClientDataSetIngredientsProd: TFloatField;
235
    ClientDataSetIngredientsLysd_ENc: TFloatField;
236
    ClientDataSetIngredientsLysd_ENt: TFloatField;
237
    ClientDataSetIngredientsCa: TFloatField;
238
    ClientDataSetIngredientsP: TFloatField;
239
    ClientDataSetIngredientsdP: TFloatField;
240
    ClientDataSetIngredientsdPphy: TFloatField;
241
    DataSourceIngredients: TDataSource;
242
    ClientDataSetComposition: TClientDataSet;
243
    ClientDataSetCompositionFeed: TIntegerField;
244
    ClientDataSetCompositionIngredient: TIntegerField;
245
    ClientDataSetCompositionUser: TBooleanField;
246
    ClientDataSetCompositionIngredientName: TWideStringField;
247
    ClientDataSetCompositionRank: TIntegerField;
248
    ClientDataSetCompositionMS: TFloatField;
249
    ClientDataSetCompositionLevel: TFloatField;
250
    DataSourceComposition: TDataSource;
251
    ClientDataSetPhytase: TClientDataSet;
252
    ClientDataSetPhytaseId: TAutoIncField;
253
    ClientDataSetPhytaseType: TFloatField;
254
    ClientDataSetPhytaseCoef: TFloatField;
255
    DataSourcePhytase: TDataSource;
256
    ClientDataSetFeeds: TClientDataSet;
257
    ClientDataSetFeedsId: TIntegerField;
258
    ClientDataSetFeedsName: TWideStringField;
259
    ClientDataSetFeedsDescription: TWideStringField;
260
    ClientDataSetFeedsPresentation: TIntegerField;
261
    ClientDataSetFeedsBonusC: TFloatField;
262
    ClientDataSetFeedsBonusT: TFloatField;
263
    ClientDataSetFeedsMS: TFloatField;
264
    ClientDataSetFeedsMS2: TFloatField;
265
    ClientDataSetFeedsMM: TFloatField;
266
    ClientDataSetFeedsMAT: TFloatField;
267
    ClientDataSetFeedsMG: TFloatField;
268
    ClientDataSetFeedsCB: TFloatField;
269
    ClientDataSetFeedsNDF: TFloatField;
270
    ClientDataSetFeedsADF: TFloatField;
271
    ClientDataSetFeedsADL: TFloatField;
272
    ClientDataSetFeedsAmidon: TFloatField;
273
    ClientDataSetFeedsSucres: TFloatField;
274
    ClientDataSetFeedsEB: TFloatField;
275
    ClientDataSetFeedsdEc: TFloatField;
276
    ClientDataSetFeedsEDc: TFloatField;
277
    ClientDataSetFeedsEMc_EDc: TFloatField;
278
    ClientDataSetFeedsEMc: TFloatField;
279
    ClientDataSetFeedsENc_EMc: TFloatField;
280
    ClientDataSetFeedsENc: TFloatField;
281
    ClientDataSetFeedsdEt: TFloatField;
282
    ClientDataSetFeedsEDt: TFloatField;
283
    ClientDataSetFeedsEMt_EDt: TFloatField;
284
    ClientDataSetFeedsEMt: TFloatField;
285
    ClientDataSetFeedsENt_EMt: TFloatField;
286
    ClientDataSetFeedsENt: TFloatField;
287
    ClientDataSetFeedsEDt_EDc: TFloatField;
288
    ClientDataSetFeedsEMt_EMc: TFloatField;
289
    ClientDataSetFeedsENt_ENc: TFloatField;
290
    ClientDataSetFeedsdNc: TFloatField;
291
    ClientDataSetFeedsdNt: TFloatField;
292
    ClientDataSetFeedsLys: TFloatField;
293
    ClientDataSetFeedsThr: TFloatField;
294
    ClientDataSetFeedsMet: TFloatField;
295
    ClientDataSetFeedsCys: TFloatField;
296
    ClientDataSetFeedsMetCys: TFloatField;
297
    ClientDataSetFeedsTrp: TFloatField;
298
    ClientDataSetFeedsIle: TFloatField;
299
    ClientDataSetFeedsVal: TFloatField;
300
    ClientDataSetFeedsLeu: TFloatField;
301
    ClientDataSetFeedsPhe: TFloatField;
302
    ClientDataSetFeedsTyr: TFloatField;
303
    ClientDataSetFeedsPheTyr: TFloatField;
304
    ClientDataSetFeedsHis: TFloatField;
305
    ClientDataSetFeedsArg: TFloatField;
306
    ClientDataSetFeedsAla: TFloatField;
307
    ClientDataSetFeedsAsp: TFloatField;
308
    ClientDataSetFeedsGlu: TFloatField;
309
    ClientDataSetFeedsGly: TFloatField;
310
    ClientDataSetFeedsSer: TFloatField;
311
    ClientDataSetFeedsPro: TFloatField;
312
    ClientDataSetFeedsLysd: TFloatField;
313
    ClientDataSetFeedsThrd: TFloatField;
314
    ClientDataSetFeedsMetd: TFloatField;
315
    ClientDataSetFeedsCysd: TFloatField;
316
    ClientDataSetFeedsMetCysd: TFloatField;
317
    ClientDataSetFeedsTrpd: TFloatField;
318
    ClientDataSetFeedsIled: TFloatField;
319
    ClientDataSetFeedsVald: TFloatField;
320
    ClientDataSetFeedsLeud: TFloatField;
321
    ClientDataSetFeedsPhed: TFloatField;
322
    ClientDataSetFeedsTyrd: TFloatField;
323
    ClientDataSetFeedsPheTyrd: TFloatField;
324
    ClientDataSetFeedsHisd: TFloatField;
325
    ClientDataSetFeedsArgd: TFloatField;
326
    ClientDataSetFeedsAlad: TFloatField;
327
    ClientDataSetFeedsAspd: TFloatField;
328
    ClientDataSetFeedsGlud: TFloatField;
329
    ClientDataSetFeedsGlyd: TFloatField;
330
    ClientDataSetFeedsSerd: TFloatField;
331
    ClientDataSetFeedsProd: TFloatField;
332
    ClientDataSetFeedsLysd_ENc: TFloatField;
333
    ClientDataSetFeedsLysd_ENt: TFloatField;
334
    ClientDataSetFeedsThrd_Lysd: TFloatField;
335
    ClientDataSetFeedsMetd_Lysd: TFloatField;
336
    ClientDataSetFeedsCysd_Lysd: TFloatField;
337
    ClientDataSetFeedsMetCysd_Lysd: TFloatField;
338
    ClientDataSetFeedsTrpd_Lysd: TFloatField;
339
    ClientDataSetFeedsIled_Lysd: TFloatField;
340
    ClientDataSetFeedsVald_Lysd: TFloatField;
341
    ClientDataSetFeedsLeud_Lysd: TFloatField;
342
    ClientDataSetFeedsPhed_Lysd: TFloatField;
343
    ClientDataSetFeedsTyrd_Lysd: TFloatField;
344
    ClientDataSetFeedsPheTyrd_Lysd: TFloatField;
345
    ClientDataSetFeedsHisd_Lysd: TFloatField;
346
    ClientDataSetFeedsArgd_Lysd: TFloatField;
347
    ClientDataSetFeedsAlad_Lysd: TFloatField;
348
    ClientDataSetFeedsAspd_Lysd: TFloatField;
349
    ClientDataSetFeedsGlud_Lysd: TFloatField;
350
    ClientDataSetFeedsGlyd_Lysd: TFloatField;
351
    ClientDataSetFeedsSerd_Lysd: TFloatField;
352
    ClientDataSetFeedsProd_Lysd: TFloatField;
353
    ClientDataSetFeedsCa: TFloatField;
354
    ClientDataSetFeedsP: TFloatField;
355
    ClientDataSetFeedsPd: TFloatField;
356
    ClientDataSetFeedsCa_Pd: TFloatField;
357
    ClientDataSetFeedsPd_ENc: TFloatField;
358
    ClientDataSetFeedsPd_ENt: TFloatField;
359
    ClientDataSetFeedsPhytaseId: TIntegerField;
360
    ClientDataSetFeedsPhytaseType: TFloatField;
361
    ClientDataSetFeedsPhytaseConcentration: TFloatField;
362
    ClientDataSetFeedsPhytaseIncorporation: TFloatField;
363
    ClientDataSetFeedsPhytaseLevel: TFloatField;
364
    ClientDataSetFeedsLevelSum: TFloatField;
365
    ClientDataSetFeedsTotal: TFloatField;
366
    ClientDataSetFeedsRemain: TFloatField;
367
    DataSourceFeeds: TDataSource;
368
    ClientDataSetInraAfzComment: TStringField;
369
    procedure DataModuleCreate(Sender: TObject);
370
    procedure DataModuleDestroy(Sender: TObject);
371
    procedure ClientDataSetIngredientsFilterRecord(DataSet: TDataSet; var Accept: Boolean);
372
    procedure ClientDataSetFeedsCalcFields(DataSet: TDataSet);
373
    procedure AggregateLevelSumUpdate(Agg: TAggregate);
374
  private
375
    { D?clarations priv?es }
376
  public
377
    { D?clarations publiques }
378
    DBUser: TSQLiteDatabase;
379
    TableIngredients: TSQLiteTable;
380
    TableFeeds: TSQLiteTable;
381
    TableComposition: TSQLiteTable;
382
    RapMS, RapMAT: Double;
383
    ClassList, UserList, FeedList: TStrings;
384
    FilterOnClass, FilterOnDatabase, FilterOnName: Boolean;
385
    FilteredClass, FilteredDatabase: Integer;
386
    FilteredName: String;
387
    procedure CalcInraAfz;
388
    procedure CalcOriginal;
389
    procedure CalcCopy;
390
    procedure CalcFeed;
391
    function InputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
392
    function InputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
393
    function InputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
394
    function InputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
395
    function InputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
396
    function OutputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
397
    function OutputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
398
    function OutputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
399
    function OutputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
400
    function OutputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
401
    function StrTrunc(S: String; Max: Integer): String;
402
  end;
403
404
var
405
  DataModuleDeclaration: TDataModuleDeclaration;
406
  MajorVersion, MinorVersion, ReleaseVersion, BuildVersion: Integer ;
407
408
implementation
409
410
{$R *.dfm}
411
412
uses
413
  SHFolder, StrUtils, UnitOptions;
414
415
procedure TDataModuleDeclaration.CalcInraAfz;
416
// Renseigner l'enregistrement courant de ClientDataSetIngredients
417
// ? partir de l'enregistrement courant de ClientDataSetInraAfz
418
// en tenant compte des unit?s configur?es
419
begin
420
  // Analyse proximale
421
  RapMS := ClientDataSetInraAfzMS.Value;
422
  ClientDataSetIngredientsMS.Value := OutputProximal(RapMS, 1, 1, FormOptions.Proximal);
423
  ClientDataSetIngredientsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
424
  if ClientDataSetInraAfzMM.IsNull
425
  then
426
    ClientDataSetIngredientsMM.Clear
427
  else
428
    ClientDataSetIngredientsMM.Value := OutputProximal(ClientDataSetInraAfzMM.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
429
  if ClientDataSetInraAfzMAT.IsNull
430
  then
431
    ClientDataSetIngredientsMAT.Clear
432
  else
433
  begin
434
    RapMAT := ClientDataSetInraAfzMAT.Value;
435
    ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
436
  end;
437
  if ClientDataSetInraAfzMG.IsNull
438
  then
439
    ClientDataSetIngredientsMG.Clear
440
  else
441
    ClientDataSetIngredientsMG.Value := OutputProximal(ClientDataSetInraAfzMG.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
442
  if ClientDataSetInraAfzCB.IsNull
443
  then
444
    ClientDataSetIngredientsCB.Clear
445
  else
446
    ClientDataSetIngredientsCB.Value := OutputProximal(ClientDataSetInraAfzCB.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
447
  if ClientDataSetInraAfzNDF.IsNull
448
  then
449
    ClientDataSetIngredientsNDF.Clear
450
  else
451
    ClientDataSetIngredientsNDF.Value := OutputProximal(ClientDataSetInraAfzNDF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
452
  if ClientDataSetInraAfzADF.IsNull
453
  then
454
    ClientDataSetIngredientsADF.Clear
455
  else
456
    ClientDataSetIngredientsADF.Value := OutputProximal(ClientDataSetInraAfzADF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
457
  if ClientDataSetInraAfzADL.IsNull
458
  then
459
    ClientDataSetIngredientsADL.Clear
460
  else
461
    ClientDataSetIngredientsADL.Value := OutputProximal(ClientDataSetInraAfzADL.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
462
  if ClientDataSetInraAfzAmidon.IsNull
463
  then
464
    ClientDataSetIngredientsAmidon.Clear
465
  else
466
    ClientDataSetIngredientsAmidon.Value := OutputProximal(ClientDataSetInraAfzAmidon.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
467
  if ClientDataSetInraAfzSucres.IsNull
468
  then
469
    ClientDataSetIngredientsSucres.Clear
470
  else
471
    ClientDataSetIngredientsSucres.Value := OutputProximal(ClientDataSetInraAfzSucres.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
472
  // Energie
473
  ClientDataSetIngredientsEB.Value := OutputEnergy(ClientDataSetInraAfzEB.Value, RapMS, FormOptions.Expression, FormOptions.Energy);
474
  ClientDataSetIngredientsBonus.Value := 0;
475
  ClientDataSetIngredientsdEc.Value := ClientDataSetInraAfzdEc.Value * 100;
476
  ClientDataSetIngredientsEDc.Value := ClientDataSetIngredientsEB.Value * ClientDataSetIngredientsdEc.Value / 100;
477
  ClientDataSetIngredientsEMc_EDc.Value := ClientDataSetInraAfzEMc_EDc.Value * 100;
478
  ClientDataSetIngredientsEMc.Value := ClientDataSetIngredientsEDc.Value * ClientDataSetIngredientsEMc_EDc.Value / 100;
479
  ClientDataSetIngredientsENc_EMc.Value := ClientDataSetInraAfzENc_EMc.Value * 100;
480
  ClientDataSetIngredientsENc.Value := ClientDataSetIngredientsEMc.Value * ClientDataSetIngredientsENc_EMc.Value / 100;
481
  ClientDataSetIngredientsEDt_EDc.Value := ClientDataSetInraAfzEDt_EDc.Value * 100;
482
  ClientDataSetIngredientsEDt.Value := ClientDataSetIngredientsEDc.Value * ClientDataSetIngredientsEDt_EDc.Value / 100;
483
  ClientDataSetIngredientsEMt_EDt.Value := ClientDataSetInraAfzEMt_EDt.Value * 100;
484
  ClientDataSetIngredientsEMt.Value := ClientDataSetIngredientsEDt.Value * ClientDataSetIngredientsEMt_EDt.Value / 100;
485
  ClientDataSetIngredientsENt_EMt.Value := ClientDataSetInraAfzENt_EMt.Value * 100;
486
  ClientDataSetIngredientsENt.Value := ClientDataSetIngredientsEMt.Value * ClientDataSetIngredientsENt_EMt.Value / 100;
487
  if ClientDataSetIngredientsEB.Value = 0
488
  then
489
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsdEc.Value
490
  else
491
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsEDt.Value / ClientDataSetIngredientsEB.Value * 100;
492
  if ClientDataSetIngredientsEMc.Value = 0
493
  then
494
    ClientDataSetIngredientsEMt_EMc.Value := 100
495
  else
496
    ClientDataSetIngredientsEMt_EMc.Value := ClientDataSetIngredientsEMt.Value / ClientDataSetIngredientsEMc.Value * 100;
497
  if ClientDataSetIngredientsENc.Value = 0
498
  then
499
    ClientDataSetIngredientsENt_ENc.Value := 100
500
  else
501
    ClientDataSetIngredientsENt_ENc.Value := ClientDataSetIngredientsENt.Value / ClientDataSetIngredientsENc.Value * 100;
502
  // Digestibilit? f?cale de l'azote
503
  if ClientDataSetInraAfzdNc.IsNull
504
  then
505
    ClientDataSetIngredientsdNc.Clear
506
  else
507
    ClientDataSetIngredientsdNc.Value := ClientDataSetInraAfzdNc.Value * 100;
508
  if ClientDataSetInraAfzdNt.IsNull
509
  then
510
    ClientDataSetIngredientsdNt.Clear
511
  else
512
    ClientDataSetIngredientsdNt.Value := ClientDataSetInraAfzdNt.Value * 100;
513
  // Acides amin?s
514
  if RapMAT = 0
515
  then // En l'absence de MAT, il n'y a pas d'acides amin?s
516
  begin
517
    // Teneurs
518
    ClientDataSetIngredientsLys.Clear;
519
    ClientDataSetIngredientsThr.Clear;
520
    ClientDataSetIngredientsMet.Clear;
521
    ClientDataSetIngredientsCys.Clear;
522
    ClientDataSetIngredientsMetCys.Clear;
523
    ClientDataSetIngredientsTrp.Clear;
524
    ClientDataSetIngredientsIle.Clear;
525
    ClientDataSetIngredientsVal.Clear;
526
    ClientDataSetIngredientsLeu.Clear;
527
    ClientDataSetIngredientsPhe.Clear;
528
    ClientDataSetIngredientsTyr.Clear;
529
    ClientDataSetIngredientsPheTyr.Clear;
530
    ClientDataSetIngredientsHis.Clear;
531
    ClientDataSetIngredientsArg.Clear;
532
    ClientDataSetIngredientsAla.Clear;
533
    ClientDataSetIngredientsAsp.Clear;
534
    ClientDataSetIngredientsGlu.Clear;
535
    ClientDataSetIngredientsGly.Clear;
536
    ClientDataSetIngredientsSer.Clear;
537
    ClientDataSetIngredientsPro.Clear;
538
    // % MAT
539
    ClientDataSetIngredientsLys_MAT.Clear;
540
    ClientDataSetIngredientsThr_MAT.Clear;
541
    ClientDataSetIngredientsMet_MAT.Clear;
542
    ClientDataSetIngredientsCys_MAT.Clear;
543
    ClientDataSetIngredientsMetCys_MAT.Clear;
544
    ClientDataSetIngredientsTrp_MAT.Clear;
545
    ClientDataSetIngredientsIle_MAT.Clear;
546
    ClientDataSetIngredientsVal_MAT.Clear;
547
    ClientDataSetIngredientsLeu_MAT.Clear;
548
    ClientDataSetIngredientsPhe_MAT.Clear;
549
    ClientDataSetIngredientsTyr_MAT.Clear;
550
    ClientDataSetIngredientsPheTyr_MAT.Clear;
551
    ClientDataSetIngredientsHis_MAT.Clear;
552
    ClientDataSetIngredientsArg_MAT.Clear;
553
    ClientDataSetIngredientsAla_MAT.Clear;
554
    ClientDataSetIngredientsAsp_MAT.Clear;
555
    ClientDataSetIngredientsGlu_MAT.Clear;
556
    ClientDataSetIngredientsGly_MAT.Clear;
557
    ClientDataSetIngredientsSer_MAT.Clear;
558
    ClientDataSetIngredientsPro_MAT.Clear;
559
    // Digestibilit?s
560
    ClientDataSetIngredientsdLys.Clear;
561
    ClientDataSetIngredientsdThr.Clear;
562
    ClientDataSetIngredientsdMet.Clear;
563
    ClientDataSetIngredientsdCys.Clear;
564
    ClientDataSetIngredientsdMetCys.Clear;
565
    ClientDataSetIngredientsdTrp.Clear;
566
    ClientDataSetIngredientsdIle.Clear;
567
    ClientDataSetIngredientsdVal.Clear;
568
    ClientDataSetIngredientsdLeu.Clear;
569
    ClientDataSetIngredientsdPhe.Clear;
570
    ClientDataSetIngredientsdTyr.Clear;
571
    ClientDataSetIngredientsdPheTyr.Clear;
572
    ClientDataSetIngredientsdHis.Clear;
573
    ClientDataSetIngredientsdArg.Clear;
574
    ClientDataSetIngredientsdAla.Clear;
575
    ClientDataSetIngredientsdAsp.Clear;
576
    ClientDataSetIngredientsdGlu.Clear;
577
    ClientDataSetIngredientsdGly.Clear;
578
    ClientDataSetIngredientsdSer.Clear;
579
    ClientDataSetIngredientsdPro.Clear;
580
    // Teneurs digestibles
581
    ClientDataSetIngredientsLysd.Clear;
582
    ClientDataSetIngredientsThrd.Clear;
583
    ClientDataSetIngredientsMetd.Clear;
584
    ClientDataSetIngredientsCysd.Clear;
585
    ClientDataSetIngredientsMetCysd.Clear;
586
    ClientDataSetIngredientsTrpd.Clear;
587
    ClientDataSetIngredientsIled.Clear;
588
    ClientDataSetIngredientsVald.Clear;
589
    ClientDataSetIngredientsLeud.Clear;
590
    ClientDataSetIngredientsPhed.Clear;
591
    ClientDataSetIngredientsTyrd.Clear;
592
    ClientDataSetIngredientsPheTyrd.Clear;
593
    ClientDataSetIngredientsHisd.Clear;
594
    ClientDataSetIngredientsArgd.Clear;
595
    ClientDataSetIngredientsAlad.Clear;
596
    ClientDataSetIngredientsAspd.Clear;
597
    ClientDataSetIngredientsGlud.Clear;
598
    ClientDataSetIngredientsGlyd.Clear;
599
    ClientDataSetIngredientsSerd.Clear;
600
    ClientDataSetIngredientsProd.Clear;
601
  end
602
  else
603
  begin
604
    // Lys
605
    if ClientDataSetInraAfzLys.IsNull
606
    then
607
    begin
608
      ClientDataSetIngredientsLys.Clear;
609
      ClientDataSetIngredientsLys_MAT.Clear;
610
      ClientDataSetIngredientsdLys.Clear;
611
      ClientDataSetIngredientsLysd.Clear;
612
    end
613
    else
614
    begin
615
      ClientDataSetIngredientsLys.Value := OutputAA(ClientDataSetInraAfzLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
616
      ClientDataSetIngredientsLys_MAT.Value := InputAA(ClientDataSetIngredientsLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
617
      if ClientDataSetInraAfzdLys.IsNull
618
      then
619
        ClientDataSetIngredientsdLys.Value := dLys * 100
620
      else
621
        ClientDataSetIngredientsdLys.Value := ClientDataSetInraAfzdLys.Value * 100;
622
      ClientDataSetIngredientsLysd.Value := ClientDataSetIngredientsdLys.Value / 100 * ClientDataSetIngredientsLys.Value;
623
    end;
624
    // Thr
625
    if ClientDataSetInraAfzThr.IsNull
626
    then
627
    begin
628
      ClientDataSetIngredientsThr.Clear;
629
      ClientDataSetIngredientsThr_MAT.Clear;
630
      ClientDataSetIngredientsdThr.Clear;
631
      ClientDataSetIngredientsThrd.Clear;
632
    end
633
    else
634
    begin
635
      ClientDataSetIngredientsThr.Value := OutputAA(ClientDataSetInraAfzThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
636
      ClientDataSetIngredientsThr_MAT.Value := InputAA(ClientDataSetIngredientsThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
637
      if ClientDataSetInraAfzdThr.IsNull
638
      then
639
        ClientDataSetIngredientsdThr.Value := dThr * 100
640
      else
641
        ClientDataSetIngredientsdThr.Value := ClientDataSetInraAfzdThr.Value * 100;
642
      ClientDataSetIngredientsThrd.Value := ClientDataSetIngredientsdThr.Value / 100 * ClientDataSetIngredientsThr.Value;
643
    end;
644
    // Met
645
    if ClientDataSetInraAfzMet.IsNull
646
    then
647
    begin
648
      ClientDataSetIngredientsMet.Clear;
649
      ClientDataSetIngredientsMet_MAT.Clear;
650
      ClientDataSetIngredientsdMet.Clear;
651
      ClientDataSetIngredientsMetd.Clear;
652
    end
653
    else
654
    begin
655
      ClientDataSetIngredientsMet.Value := OutputAA(ClientDataSetInraAfzMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
656
      ClientDataSetIngredientsMet_MAT.Value := InputAA(ClientDataSetIngredientsMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
657
      if ClientDataSetInraAfzdMet.IsNull
658
      then
659
        ClientDataSetIngredientsdMet.Value := dMet * 100
660
      else
661
        ClientDataSetIngredientsdMet.Value := ClientDataSetInraAfzdMet.Value * 100;
662
      ClientDataSetIngredientsMetd.Value := ClientDataSetIngredientsdMet.Value / 100 * ClientDataSetIngredientsMet.Value;
663
    end;
664
    // Cys
665
    if ClientDataSetInraAfzCys.IsNull
666
    then
667
    begin
668
      ClientDataSetIngredientsCys.Clear;
669
      ClientDataSetIngredientsCys_MAT.Clear;
670
      ClientDataSetIngredientsdCys.Clear;
671
      ClientDataSetIngredientsCysd.Clear;
672
    end
673
    else
674
    begin
675
      ClientDataSetIngredientsCys.Value := OutputAA(ClientDataSetInraAfzCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
676
      ClientDataSetIngredientsCys_MAT.Value := InputAA(ClientDataSetIngredientsCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
677
      if ClientDataSetInraAfzdCys.IsNull
678
      then
679
        ClientDataSetIngredientsdCys.Value := dCys * 100
680
      else
681
        ClientDataSetIngredientsdCys.Value := ClientDataSetInraAfzdCys.Value * 100;
682
      ClientDataSetIngredientsCysd.Value := ClientDataSetIngredientsdCys.Value / 100 * ClientDataSetIngredientsCys.Value;
683
    end;
684
    // Met + Cys
685
    if ClientDataSetInraAfzMetCys.IsNull
686
    then
687
    begin
688
      ClientDataSetIngredientsMetCys.Clear;
689
      ClientDataSetIngredientsMetCys_MAT.Clear;
690
      ClientDataSetIngredientsdMetCys.Clear;
691
      ClientDataSetIngredientsMetCysd.Clear;
692
    end
693
    else
694
    begin
695
      ClientDataSetIngredientsMetCys.Value := OutputAA(ClientDataSetInraAfzMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
696
      ClientDataSetIngredientsMetCys_MAT.Value := InputAA(ClientDataSetIngredientsMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
697
      if ClientDataSetInraAfzdMetCys.IsNull
698
      then
699
        ClientDataSetIngredientsdMetCys.Value := dMetCys * 100
700
      else
701
        ClientDataSetIngredientsdMetCys.Value := ClientDataSetInraAfzdMetCys.Value * 100;
702
      ClientDataSetIngredientsMetCysd.Value := ClientDataSetIngredientsdMetCys.Value / 100 * ClientDataSetIngredientsMetCys.Value;
703
    end;
704
    // Trp
705
    if ClientDataSetInraAfzTrp.IsNull
706
    then
707
    begin
708
      ClientDataSetIngredientsTrp.Clear;
709
      ClientDataSetIngredientsTrp_MAT.Clear;
710
      ClientDataSetIngredientsdTrp.Clear;
711
      ClientDataSetIngredientsTrpd.Clear;
712
    end
713
    else
714
    begin
715
      ClientDataSetIngredientsTrp.Value := OutputAA(ClientDataSetInraAfzTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
716
      ClientDataSetIngredientsTrp_MAT.Value := InputAA(ClientDataSetIngredientsTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
717
      if ClientDataSetInraAfzdTrp.IsNull
718
      then
719
        ClientDataSetIngredientsdTrp.Value := dTrp * 100
720
      else
721
        ClientDataSetIngredientsdTrp.Value := ClientDataSetInraAfzdTrp.Value * 100;
722
      ClientDataSetIngredientsTrpd.Value := ClientDataSetIngredientsdTrp.Value / 100 * ClientDataSetIngredientsTrp.Value;
723
    end;
724
    // Ile
725
    if ClientDataSetInraAfzIle.IsNull
726
    then
727
    begin
728
      ClientDataSetIngredientsIle.Clear;
729
      ClientDataSetIngredientsIle_MAT.Clear;
730
      ClientDataSetIngredientsdIle.Clear;
731
      ClientDataSetIngredientsIled.Clear;
732
    end
733
    else
734
    begin
735
      ClientDataSetIngredientsIle.Value := OutputAA(ClientDataSetInraAfzIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
736
      ClientDataSetIngredientsIle_MAT.Value := InputAA(ClientDataSetIngredientsIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
737
      if ClientDataSetInraAfzdIle.IsNull
738
      then
739
        ClientDataSetIngredientsdIle.Value := dIle * 100
740
      else
741
        ClientDataSetIngredientsdIle.Value := ClientDataSetInraAfzdIle.Value * 100;
742
      ClientDataSetIngredientsIled.Value := ClientDataSetIngredientsdIle.Value / 100 * ClientDataSetIngredientsIle.Value;
743
    end;
744
    // Val
745
    if ClientDataSetInraAfzVal.IsNull
746
    then
747
    begin
748
      ClientDataSetIngredientsVal.Clear;
749
      ClientDataSetIngredientsVal_MAT.Clear;
750
      ClientDataSetIngredientsdVal.Clear;
751
      ClientDataSetIngredientsVald.Clear;
752
    end
753
    else
754
    begin
755
      ClientDataSetIngredientsVal.Value := OutputAA(ClientDataSetInraAfzVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
756
      ClientDataSetIngredientsVal_MAT.Value := InputAA(ClientDataSetIngredientsVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
757
      if ClientDataSetInraAfzdVal.IsNull
758
      then
759
        ClientDataSetIngredientsdVal.Value := dVal * 100
760
      else
761
        ClientDataSetIngredientsdVal.Value := ClientDataSetInraAfzdVal.Value * 100;
762
      ClientDataSetIngredientsVald.Value := ClientDataSetIngredientsdVal.Value / 100 * ClientDataSetIngredientsVal.Value;
763
    end;
764
    // Leu
765
    if ClientDataSetInraAfzLeu.IsNull
766
    then
767
    begin
768
      ClientDataSetIngredientsLeu.Clear;
769
      ClientDataSetIngredientsLeu_MAT.Clear;
770
      ClientDataSetIngredientsdLeu.Clear;
771
      ClientDataSetIngredientsLeud.Clear;
772
    end
773
    else
774
    begin
775
      ClientDataSetIngredientsLeu.Value := OutputAA(ClientDataSetInraAfzLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
776
      ClientDataSetIngredientsLeu_MAT.Value := InputAA(ClientDataSetIngredientsLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
777
      if ClientDataSetInraAfzdLeu.IsNull
778
      then
779
        ClientDataSetIngredientsdLeu.Value := dLeu * 100
780
      else
781
        ClientDataSetIngredientsdLeu.Value := ClientDataSetInraAfzdLeu.Value * 100;
782
      ClientDataSetIngredientsLeud.Value := ClientDataSetIngredientsdLeu.Value / 100 * ClientDataSetIngredientsLeu.Value;
783
    end;
784
    // Phe
785
    if ClientDataSetInraAfzPhe.IsNull
786
    then
787
    begin
788
      ClientDataSetIngredientsPhe.Clear;
789
      ClientDataSetIngredientsPhe_MAT.Clear;
790
      ClientDataSetIngredientsdPhe.Clear;
791
      ClientDataSetIngredientsPhed.Clear;
792
    end
793
    else
794
    begin
795
      ClientDataSetIngredientsPhe.Value := OutputAA(ClientDataSetInraAfzPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
796
      ClientDataSetIngredientsPhe_MAT.Value := InputAA(ClientDataSetIngredientsPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
797
      if ClientDataSetInraAfzdPhe.IsNull
798
      then
799
        ClientDataSetIngredientsdPhe.Value := dPhe * 100
800
      else
801
        ClientDataSetIngredientsdPhe.Value := ClientDataSetInraAfzdPhe.Value * 100;
802
      ClientDataSetIngredientsPhed.Value := ClientDataSetIngredientsdPhe.Value / 100 * ClientDataSetIngredientsPhe.Value;
803
    end;
804
    // Tyr
805
    if ClientDataSetInraAfzTyr.IsNull
806
    then
807
    begin
808
      ClientDataSetIngredientsTyr.Clear;
809
      ClientDataSetIngredientsTyr_MAT.Clear;
810
      ClientDataSetIngredientsdTyr.Clear;
811
      ClientDataSetIngredientsTyrd.Clear;
812
    end
813
    else
814
    begin
815
      ClientDataSetIngredientsTyr.Value := OutputAA(ClientDataSetInraAfzTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
816
      ClientDataSetIngredientsTyr_MAT.Value := InputAA(ClientDataSetIngredientsTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
817
      if ClientDataSetInraAfzdTyr.IsNull
818
      then
819
        ClientDataSetIngredientsdTyr.Value := dTyr * 100
820
      else
821
        ClientDataSetIngredientsdTyr.Value := ClientDataSetInraAfzdTyr.Value * 100;
822
      ClientDataSetIngredientsTyrd.Value := ClientDataSetIngredientsdTyr.Value / 100 * ClientDataSetIngredientsTyr.Value;
823
    end;
824
    // Phe + Tyr
825
    if ClientDataSetInraAfzPheTyr.IsNull
826
    then
827
    begin
828
      ClientDataSetIngredientsPheTyr.Clear;
829
      ClientDataSetIngredientsPheTyr_MAT.Clear;
830
      ClientDataSetIngredientsdPheTyr.Clear;
831
      ClientDataSetIngredientsPheTyrd.Clear;
832
    end
833
    else
834
    begin
835
      ClientDataSetIngredientsPheTyr.Value := OutputAA(ClientDataSetInraAfzPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
836
      ClientDataSetIngredientsPheTyr_MAT.Value := InputAA(ClientDataSetIngredientsPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
837
      if ClientDataSetInraAfzdPheTyr.IsNull
838
      then
839
        ClientDataSetIngredientsdPheTyr.Value := dPheTyr * 100
840
      else
841
        ClientDataSetIngredientsdPheTyr.Value := ClientDataSetInraAfzdPheTyr.Value * 100;
842
      ClientDataSetIngredientsPheTyrd.Value := ClientDataSetIngredientsdPheTyr.Value / 100 * ClientDataSetIngredientsPheTyr.Value;
843
    end;
844
    // His
845
    if ClientDataSetInraAfzHis.IsNull
846
    then
847
    begin
848
      ClientDataSetIngredientsHis.Clear;
849
      ClientDataSetIngredientsHis_MAT.Clear;
850
      ClientDataSetIngredientsdHis.Clear;
851
      ClientDataSetIngredientsHisd.Clear;
852
    end
853
    else
854
    begin
855
      ClientDataSetIngredientsHis.Value := OutputAA(ClientDataSetInraAfzHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
856
      ClientDataSetIngredientsHis_MAT.Value := InputAA(ClientDataSetIngredientsHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
857
      if ClientDataSetInraAfzdHis.IsNull
858
      then
859
        ClientDataSetIngredientsdHis.Value := dHis * 100
860
      else
861
        ClientDataSetIngredientsdHis.Value := ClientDataSetInraAfzdHis.Value * 100;
862
      ClientDataSetIngredientsHisd.Value := ClientDataSetIngredientsdHis.Value / 100 * ClientDataSetIngredientsHis.Value;
863
    end;
864
    // Arg
865
    if ClientDataSetInraAfzArg.IsNull
866
    then
867
    begin
868
      ClientDataSetIngredientsArg.Clear;
869
      ClientDataSetIngredientsArg_MAT.Clear;
870
      ClientDataSetIngredientsdArg.Clear;
871
      ClientDataSetIngredientsArgd.Clear;
872
    end
873
    else
874
    begin
875
      ClientDataSetIngredientsArg.Value := OutputAA(ClientDataSetInraAfzArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
876
      ClientDataSetIngredientsArg_MAT.Value := InputAA(ClientDataSetIngredientsArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
877
      if ClientDataSetInraAfzdArg.IsNull
878
      then
879
        ClientDataSetIngredientsdArg.Value := dArg * 100
880
      else
881
        ClientDataSetIngredientsdArg.Value := ClientDataSetInraAfzdArg.Value * 100;
882
      ClientDataSetIngredientsArgd.Value := ClientDataSetIngredientsdArg.Value / 100 * ClientDataSetIngredientsArg.Value;
883
    end;
884
    // Ala
885
    if ClientDataSetInraAfzAla.IsNull
886
    then
887
    begin
888
      ClientDataSetIngredientsAla.Clear;
889
      ClientDataSetIngredientsAla_MAT.Clear;
890
      ClientDataSetIngredientsdAla.Clear;
891
      ClientDataSetIngredientsAlad.Clear;
892
    end
893
    else
894
    begin
895
      ClientDataSetIngredientsAla.Value := OutputAA(ClientDataSetInraAfzAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
896
      ClientDataSetIngredientsAla_MAT.Value := InputAA(ClientDataSetIngredientsAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
897
      if ClientDataSetInraAfzdAla.IsNull
898
      then
899
        ClientDataSetIngredientsdAla.Value := dAla * 100
900
      else
901
        ClientDataSetIngredientsdAla.Value := ClientDataSetInraAfzdAla.Value * 100;
902
      ClientDataSetIngredientsAlad.Value := ClientDataSetIngredientsdAla.Value / 100 * ClientDataSetIngredientsAla.Value;
903
    end;
904
    // Asp
905
    if ClientDataSetInraAfzAsp.IsNull
906
    then
907
    begin
908
      ClientDataSetIngredientsAsp.Clear;
909
      ClientDataSetIngredientsAsp_MAT.Clear;
910
      ClientDataSetIngredientsdAsp.Clear;
911
      ClientDataSetIngredientsAspd.Clear;
912
    end
913
    else
914
    begin
915
      ClientDataSetIngredientsAsp.Value := OutputAA(ClientDataSetInraAfzAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
916
      ClientDataSetIngredientsAsp_MAT.Value := InputAA(ClientDataSetIngredientsAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
917
      if ClientDataSetInraAfzdAsp.IsNull
918
      then
919
        ClientDataSetIngredientsdAsp.Value := dAsp * 100
920
      else
921
        ClientDataSetIngredientsdAsp.Value := ClientDataSetInraAfzdAsp.Value * 100;
922
      ClientDataSetIngredientsAspd.Value := ClientDataSetIngredientsdAsp.Value / 100 * ClientDataSetIngredientsAsp.Value;
923
    end;
924
    // Glu
925
    if ClientDataSetInraAfzGlu.IsNull
926
    then
927
    begin
928
      ClientDataSetIngredientsGlu.Clear;
929
      ClientDataSetIngredientsGlu_MAT.Clear;
930
      ClientDataSetIngredientsdGlu.Clear;
931
      ClientDataSetIngredientsGlud.Clear;
932
    end
933
    else
934
    begin
935
      ClientDataSetIngredientsGlu.Value := OutputAA(ClientDataSetInraAfzGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
936
      ClientDataSetIngredientsGlu_MAT.Value := InputAA(ClientDataSetIngredientsGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
937
      if ClientDataSetInraAfzdGlu.IsNull
938
      then
939
        ClientDataSetIngredientsdGlu.Value := dGlu * 100
940
      else
941
        ClientDataSetIngredientsdGlu.Value := ClientDataSetInraAfzdGlu.Value * 100;
942
      ClientDataSetIngredientsGlud.Value := ClientDataSetIngredientsdGlu.Value / 100 * ClientDataSetIngredientsGlu.Value;
943
    end;
944
    // Gly
945
    if ClientDataSetInraAfzGly.IsNull
946
    then
947
    begin
948
      ClientDataSetIngredientsGly.Clear;
949
      ClientDataSetIngredientsGly_MAT.Clear;
950
      ClientDataSetIngredientsdGly.Clear;
951
      ClientDataSetIngredientsGlyd.Clear;
952
    end
953
    else
954
    begin
955
      ClientDataSetIngredientsGly.Value := OutputAA(ClientDataSetInraAfzGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
956
      ClientDataSetIngredientsGly_MAT.Value := InputAA(ClientDataSetIngredientsGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
957
      if ClientDataSetInraAfzdGly.IsNull
958
      then
959
        ClientDataSetIngredientsdGly.Value := dGly * 100
960
      else
961
        ClientDataSetIngredientsdGly.Value := ClientDataSetInraAfzdGly.Value * 100;
962
      ClientDataSetIngredientsGlyd.Value := ClientDataSetIngredientsdGly.Value / 100 * ClientDataSetIngredientsGly.Value;
963
    end;
964
    // Ser
965
    if ClientDataSetInraAfzSer.IsNull
966
    then
967
    begin
968
      ClientDataSetIngredientsSer.Clear;
969
      ClientDataSetIngredientsSer_MAT.Clear;
970
      ClientDataSetIngredientsdSer.Clear;
971
      ClientDataSetIngredientsSerd.Clear;
972
    end
973
    else
974
    begin
975
      ClientDataSetIngredientsSer.Value := OutputAA(ClientDataSetInraAfzSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
976
      ClientDataSetIngredientsSer_MAT.Value := InputAA(ClientDataSetIngredientsSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
977
      if ClientDataSetInraAfzdSer.IsNull
978
      then
979
        ClientDataSetIngredientsdSer.Value := dSer * 100
980
      else
981
        ClientDataSetIngredientsdSer.Value := ClientDataSetInraAfzdSer.Value * 100;
982
      ClientDataSetIngredientsSerd.Value := ClientDataSetIngredientsdSer.Value / 100 * ClientDataSetIngredientsSer.Value;
983
    end;
984
    // Pro
985
    if ClientDataSetInraAfzPro.IsNull
986
    then
987
    begin
988
      ClientDataSetIngredientsPro.Clear;
989
      ClientDataSetIngredientsPro_MAT.Clear;
990
      ClientDataSetIngredientsdPro.Clear;
991
      ClientDataSetIngredientsProd.Clear;
992
    end
993
    else
994
    begin
995
      ClientDataSetIngredientsPro.Value := OutputAA(ClientDataSetInraAfzPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
996
      ClientDataSetIngredientsPro_MAT.Value := InputAA(ClientDataSetIngredientsPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
997
      if ClientDataSetInraAfzdPro.IsNull
998
      then
999
        ClientDataSetIngredientsdPro.Value := dPro * 100
1000
      else
1001
        ClientDataSetIngredientsdPro.Value := ClientDataSetInraAfzdPro.Value * 100;
1002
      ClientDataSetIngredientsProd.Value := ClientDataSetIngredientsdPro.Value / 100 * ClientDataSetIngredientsPro.Value;
1003
    end;
1004
  end;
1005
  // Min?raux
1006
  if ClientDataSetInraAfzCa.IsNull
1007
  then
1008
    ClientDataSetIngredientsCa.Clear
1009
  else
1010
    ClientDataSetIngredientsCa.Value := OutputMinerals(ClientDataSetInraAfzCa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1011
  if ClientDataSetInraAfzP.IsNull
1012
  then
1013
    ClientDataSetIngredientsP.Clear
1014
  else
1015
    ClientDataSetIngredientsP.Value := OutputMinerals(ClientDataSetInraAfzP.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1016
  if ClientDataSetIngredientsP.Value = 0
1017
  then // En l'absence de P, il n'y a pas de dP
1018
  begin
1019
    ClientDataSetIngredientsdP.Clear;
1020
    ClientDataSetIngredientsdPphy.Clear;
1021
  end
1022
  else
1023
  begin
1024
    if ClientDataSetInraAfzdP.IsNull
1025
    then // Par d?faut dP = 20%
1026
      ClientDataSetIngredientsdP.Value := 20
1027
    else
1028
      ClientDataSetIngredientsdP.Value := ClientDataSetInraAfzdP.Value * 100;
1029
    if ClientDataSetInraAfzdPphy.IsNull
1030
    then // Par d?faut dPphy = dP
1031
      ClientDataSetIngredientsdPphy.Value := ClientDataSetIngredientsdP.Value
1032
    else
1033
      ClientDataSetIngredientsdPphy.Value := ClientDataSetInraAfzdPphy.Value * 100;
1034
  end;
1035
  // Autres rapports
1036
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
1037
  then
1038
    ClientDataSetIngredientsLysd_ENc.Clear
1039
  else
1040
    if FormOptions.Energy = 0
1041
    then // g / MJ
1042
      if FormOptions.AA = 0
1043
      then // % (conversion)
1044
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value
1045
      else // g/kg
1046
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value
1047
    else // g / 1000 kcal
1048
      if FormOptions.AA = 0
1049
      then // % (conversion)
1050
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value * 1000
1051
      else // g/kg
1052
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value * 1000;
1053
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENt.IsNull or (ClientDataSetIngredientsENt.Value = 0)
1054
  then
1055
    ClientDataSetIngredientsLysd_ENt.Clear
1056
  else
1057
    if FormOptions.Energy = 0
1058
    then // g / MJ
1059
      if FormOptions.AA = 0
1060
      then // % (conversion)
1061
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value
1062
      else // g/kg
1063
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value
1064
    else // g / 1000 kcal
1065
      if FormOptions.AA = 0
1066
      then // % (conversion)
1067
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value * 1000
1068
      else // g/kg
1069
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value * 1000;
1070
end;
1071
1072
procedure TDataModuleDeclaration.CalcOriginal;
1073
// Renseigner l'enregistrement courant de ClientDataSetIngredients
1074
// ? partir de l'enregistrement courant de TableIngredients
1075
// en tenant compte des unit?s configur?es
1076
var
1077
  Nb: Integer;
1078
  Bonus, EB, dE, EDc, EDt, EM, EN, EqCB, EqADF, EqNDF, NUri, EUri, Res, ResD, ECH4, dMO, dN: Double;
1079
begin
1080
  // Analyse proximale -> valeurs saisies
1081
  RapMS := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MS']);
1082
  ClientDataSetIngredientsMS.Value := OutputProximal(RapMS, 1, 1, FormOptions.Proximal);
1083
  ClientDataSetIngredientsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
1084
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1085
  then
1086
    ClientDataSetIngredientsMM.Clear
1087
  else
1088
    ClientDataSetIngredientsMM.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1089
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1090
  then
1091
    ClientDataSetIngredientsMAT.Clear
1092
  else
1093
  begin
1094
    RapMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']);
1095
    ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
1096
  end;
1097
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1098
  then
1099
    ClientDataSetIngredientsMG.Clear
1100
  else
1101
    ClientDataSetIngredientsMG.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1102
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1103
  then
1104
    ClientDataSetIngredientsCB.Clear
1105
  else
1106
    ClientDataSetIngredientsCB.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1107
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1108
  then
1109
    ClientDataSetIngredientsNDF.Clear
1110
  else
1111
    ClientDataSetIngredientsNDF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1112
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1113
  then
1114
    ClientDataSetIngredientsADF.Clear
1115
  else
1116
    ClientDataSetIngredientsADF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1117
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
1118
  then
1119
    ClientDataSetIngredientsADL.Clear
1120
  else
1121
    ClientDataSetIngredientsADL.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADL']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1122
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1123
  then
1124
    ClientDataSetIngredientsAmidon.Clear
1125
  else
1126
    ClientDataSetIngredientsAmidon.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1127
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1128
  then
1129
    ClientDataSetIngredientsSucres.Clear
1130
  else
1131
    ClientDataSetIngredientsSucres.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1132
  // Energie
1133
  EB := 0;
1134
  dE := 0;
1135
  EDc := 0;
1136
  EDt := 0;
1137
  EM := 0;
1138
//  EN := 0;
1139
  NUri := 0;
1140
//  EUri := 0;
1141
  Res := 0;
1142
//  ResD := 0;
1143
//  ECH4 := 0;
1144
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['EB'])
1145
  then // EB calcul?e
1146
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1147
    or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1148
    or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1149
    then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1150
      ClientDataSetIngredientsEB.Clear
1151
    else
1152
    begin
1153
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1154
      then
1155
        EqCB := 0
1156
      else
1157
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1158
        then // Equation SANS sucres
1159
          EqCB := 17.57 + 5.35 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.68 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 18.61 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 2.84 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB'])
1160
        else // Equation AVEC sucres
1161
          EqCB := 17.56 + 5.51 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.48 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 17.74 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 2.59 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - 1.14 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']);
1162
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1163
      then
1164
        EqADF := 0
1165
      else
1166
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1167
        then // Equation SANS sucres
1168
          EqADF := 17.58 + 5.29 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.71 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 18.58 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 2.38 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF'])
1169
        else // Equation AVEC sucres
1170
          EqADF := 17.56 + 5.45 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.50 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 17.69 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 2.16 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - 1.15 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']);
1171
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1172
      then
1173
        EqNDF := 0
1174
      else
1175
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1176
        then // Equation SANS sucres
1177
          EqNDF := 17.40 + 5.73 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.76 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 18.73 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 1.61 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF'])
1178
        else // Equation AVEC sucres
1179
          EqNDF := 17.41 + 5.79 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.63 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 18.12 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 1.48 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - 0.72 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']);
1180
      Nb := 0;
1181
      if EqCB <> 0 then Inc(Nb);
1182
      if EqADF <> 0 then Inc(Nb);
1183
      if EqNDF <> 0 then Inc(Nb);
1184
      if Nb = 0
1185
      then // Equations sans valeur de fibre (ne devrait pas se produire)
1186
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1187
        then // Equation SANS amidon
1188
          if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1189
          then // Equation SANS sucres
1190
            EB := 17.64 + 4.78 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.80 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 15.88 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM'])
1191
          else // Equation AVEC sucres
1192
            EB := 17.61 + 5.05 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.53 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 15.06 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - 1.48 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres'])
1193
        else // Equation AVEC amidon
1194
          if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1195
          then // Equation SANS sucres
1196
            EB := 18.47 + 4.14 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.08 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 19.64 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - 0.92 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon'])
1197
          else // Equation AVEC sucres
1198
            EB := 18.88 + 4.24 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 20.25 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 20.37 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - 1.42 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 2.38 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres'])
1199
      else // Moyenne des ?quations significatives
1200
        EB := (EqCB + EqADF + EqNDF) / Nb;
1201
      ClientDataSetIngredientsEB.Value := OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy);
1202
    end
1203
  else // EB fournie par l'utilisateur
1204
  begin
1205
    EB := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['EB']);
1206
    ClientDataSetIngredientsEB.Value := OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy);
1207
  end;
1208
  Bonus := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Bonus']) * 100;
1209
  ClientDataSetIngredientsBonus.Value := Bonus;
1210
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1211
  then
1212
    EqCB := 0
1213
  else
1214
    EqCB := 90.1 - 157.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1215
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1216
  then
1217
    EqNDF := 0
1218
  else
1219
    EqNDF := 98.3 - 90.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1220
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1221
  then
1222
    EqADF := 0
1223
  else
1224
    EqADF := 90.8 - 143.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1225
  Nb := 0;
1226
  if EqCB <> 0 then Inc(Nb);
1227
  if EqNDF <> 0 then Inc(Nb);
1228
  if EqADF <> 0 then Inc(Nb);
1229
  if Nb = 0
1230
  then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1231
    ClientDataSetIngredientsdEc.Clear
1232
  else // Moyenne des ?quations significatives
1233
  begin
1234
    dE := (EqCB + EqNDF + EqADF) / Nb + Bonus;
1235
    ClientDataSetIngredientsdEc.Value := dE;
1236
  end;
1237
  if ClientDataSetIngredientsEB.IsNull or ClientDataSetIngredientsdEc.IsNull
1238
  then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1239
    ClientDataSetIngredientsEDc.Clear
1240
  else
1241
  begin
1242
    EDc := EB * dE / 100;
1243
    ClientDataSetIngredientsEDc.Value := OutputEnergy(EDc, RapMS, FormOptions.Expression, FormOptions.Energy);
1244
  end;
1245
  if ClientDataSetIngredientsEDc.IsNull
1246
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1247
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1248
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1249
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1250
  then // Informations insuffisantes pour calculer
1251
  begin
1252
    ClientDataSetIngredientsEMc.Clear;
1253
    ClientDataSetIngredientsEMc_EDc.Clear;
1254
  end
1255
  else
1256
  begin
1257
    NUri := 0.4 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) / 6.25;
1258
    EUri := CALORIE * (0.046 + 7.4 * NUri);
1259
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1260
    then // par d?faut, on estime les sucres ? 2 % MS
1261
      Res := 1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 0.02
1262
    else
1263
      Res := 1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']);
1264
    ResD := 0.5 * Res;
1265
    ECH4 := CALORIE * 0.16 * ResD;
1266
    EM := EDc - EUri - ECH4;
1267
    ClientDataSetIngredientsEMc.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
1268
    if EDc = 0
1269
    then // Division par 0
1270
      ClientDataSetIngredientsEMc_EDc.Clear
1271
    else
1272
      ClientDataSetIngredientsEMc_EDc.Value := EM / EDc * 100;
1273
  end;
1274
  if ClientDataSetIngredientsEDc.IsNull
1275
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1276
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1277
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1278
  then // Informations insuffisantes pour calculer
1279
  begin
1280
    ClientDataSetIngredientsENc.Clear;
1281
    ClientDataSetIngredientsENc_EMc.Clear;
1282
  end
1283
  else
1284
  begin
1285
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1286
    then
1287
      EqCB := 0
1288
    else
1289
      EqCB := 0.703 * EDc - 4.04 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.62 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 1.97 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 4.09 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1290
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1291
    then
1292
      EqNDF := 0
1293
    else
1294
      EqNDF := 0.703 * EDc - 4.10 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.64 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 1.97 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 1.34 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1295
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1296
    then
1297
      EqADF := 0
1298
    else
1299
      EqADF := 0.700 * EDc - 3.82 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.74 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 2.02 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 3.65 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1300
    Nb := 0;
1301
    if EqCB <> 0 then Inc(Nb);
1302
    if EqNDF <> 0 then Inc(Nb);
1303
    if EqADF <> 0 then Inc(Nb);
1304
    if Nb = 0
1305
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1306
    begin
1307
      ClientDataSetIngredientsENc.Clear;
1308
      ClientDataSetIngredientsENc_EMc.Clear;
1309
    end
1310
    else // Moyenne des ?quations significatives
1311
    begin
1312
      EN := (EqCB + EqNDF + EqADF) / Nb;
1313
      ClientDataSetIngredientsENc.Value := OutputEnergy(EN, RapMS, FormOptions.Expression, FormOptions.Energy);
1314
      if EM = 0
1315
      then // Division par 0
1316
        ClientDataSetIngredientsENc_EMc.Clear
1317
      else
1318
        ClientDataSetIngredientsENc_EMc.Value := EN / EM * 100;
1319
    end;
1320
  end;
1321
  if ClientDataSetIngredientsEDc.IsNull
1322
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1323
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1324
  then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1325
  begin
1326
    ClientDataSetIngredientsEDt.Clear;
1327
    ClientDataSetIngredientsEDt_EDc.Clear;
1328
  end
1329
  else
1330
  begin
1331
    dMO := (7.45 + 0.949 * dE - 4.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT'])) / 100;
1332
    EDt := EDc + CALORIE * (1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM'])) * (1 - dMO);
1333
    ClientDataSetIngredientsEDt.Value := OutputEnergy(EDt, RapMS, FormOptions.Expression, FormOptions.Energy);
1334
    if EDc = 0
1335
    then // Division par 0
1336
      ClientDataSetIngredientsEDt_EDc.Clear
1337
    else
1338
      ClientDataSetIngredientsEDt_EDc.Value := EDt / EDc * 100;
1339
  end;
1340
  if ClientDataSetIngredientsEDt.IsNull
1341
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1342
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1343
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1344
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1345
  then // Informations insuffisantes pour calculer
1346
  begin
1347
    ClientDataSetIngredientsEMt.Clear;
1348
    ClientDataSetIngredientsEMt_EDt.Clear;
1349
  end
1350
  else
1351
  begin
1352
//    NUri := 0.4 * TableIngredients.FieldByName('MAT').AsFloat / 6.25;
1353
    EUri := CALORIE * (0.052 + 7.4 * NUri);
1354
//    if TableIngredients.FieldByName('Sucres').IsNull
1355
//    then // par d?faut, on estime les sucres ? 2 % MS
1356
//      Res := 1 - TableIngredients.FieldByName('MM').AsFloat - TableIngredients.FieldByName('MAT').AsFloat - TableIngredients.FieldByName('MG').AsFloat - TableIngredients.FieldByName('Amidon').AsFloat - 0.02
1357
//    else
1358
//      Res := 1 - TableIngredients.FieldByName('MM').AsFloat - TableIngredients.FieldByName('MAT').AsFloat - TableIngredients.FieldByName('MG').AsFloat - TableIngredients.FieldByName('Amidon').AsFloat - TableIngredients.FieldByName('Sucres').AsFloat;
1359
    ResD := 0.6 * Res;
1360
    ECH4 := CALORIE * 0.32 * ResD;
1361
    EM := EDt - EUri - ECH4;
1362
    ClientDataSetIngredientsEMt.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
1363
    if EDt = 0
1364
    then // Division par 0
1365
      ClientDataSetIngredientsEMt_EDt.Clear
1366
    else
1367
      ClientDataSetIngredientsEMt_EDt.Value := EM / EDt * 100;
1368
  end;
1369
  if ClientDataSetIngredientsEDt.IsNull
1370
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1371
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1372
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1373
  then // Informations insuffisantes pour calculer
1374
  begin
1375
    ClientDataSetIngredientsENt.Clear;
1376
    ClientDataSetIngredientsENt_EMt.Clear;
1377
  end
1378
  else
1379
  begin
1380
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1381
    then
1382
      EqCB := 0
1383
    else
1384
      EqCB := 0.703 * EDt - 4.04 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.62 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 1.97 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 4.09 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1385
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1386
    then
1387
      EqNDF := 0
1388
    else
1389
      EqNDF := 0.703 * EDt - 4.10 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.64 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 1.97 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 1.34 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1390
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1391
    then
1392
      EqADF := 0
1393
    else
1394
      EqADF := 0.700 * EDt - 3.82 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.74 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 2.02 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 3.65 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1395
    Nb := 0;
1396
    if EqCB <> 0 then Inc(Nb);
1397
    if EqNDF <> 0 then Inc(Nb);
1398
    if EqADF <> 0 then Inc(Nb);
1399
    if Nb = 0
1400
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1401
    begin
1402
      ClientDataSetIngredientsENt.Clear;
1403
      ClientDataSetIngredientsENt_EMt.Clear;
1404
    end
1405
    else // Moyenne des ?quations significatives
1406
    begin
1407
      EN := (EqCB + EqNDF + EqADF) / Nb;
1408
      ClientDataSetIngredientsENt.Value := OutputEnergy(EN, RapMS, FormOptions.Expression, FormOptions.Energy);
1409
      if EM = 0
1410
      then // Division par 0
1411
        ClientDataSetIngredientsENt_EMt.Clear
1412
      else
1413
        ClientDataSetIngredientsENt_EMt.Value := EN / EM * 100;
1414
    end;
1415
  end;
1416
  if ClientDataSetIngredientsEDt.IsNull or ClientDataSetIngredientsEB.IsNull or (ClientDataSetIngredientsEB.Value = 0)
1417
  then
1418
    ClientDataSetIngredientsdEt.Clear
1419
  else
1420
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsEDt.Value / ClientDataSetIngredientsEB.Value * 100;
1421
  if ClientDataSetIngredientsEMt.IsNull or ClientDataSetIngredientsEMc.IsNull or (ClientDataSetIngredientsEMc.Value = 0)
1422
  then
1423
    ClientDataSetIngredientsEMt_EMc.Clear
1424
  else
1425
    ClientDataSetIngredientsEMt_EMc.Value := ClientDataSetIngredientsEMt.Value / ClientDataSetIngredientsEMc.Value * 100;
1426
  if ClientDataSetIngredientsENt.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
1427
  then
1428
    ClientDataSetIngredientsENt_ENc.Clear
1429
  else
1430
    ClientDataSetIngredientsENt_ENc.Value := ClientDataSetIngredientsENt.Value / ClientDataSetIngredientsENc.Value * 100;
1431
  // Digestibilit? f?cale de l'azote
1432
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1433
  then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1434
  begin
1435
    ClientDataSetIngredientsdNc.Clear;
1436
    ClientDataSetIngredientsdNt.Clear;
1437
  end
1438
  else
1439
  begin
1440
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1441
    then
1442
      EqCB := 0
1443
    else
1444
      EqCB := 76.8 + 69.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 122.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1445
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1446
    then
1447
      EqNDF := 0
1448
    else
1449
      EqNDF := 81.3 + 79.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 69.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1450
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1451
    then
1452
      EqADF := 0
1453
    else
1454
      EqADF := 77.4 + 70.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 116.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1455
    Nb := 0;
1456
    if EqCB <> 0 then Inc(Nb);
1457
    if EqNDF <> 0 then Inc(Nb);
1458
    if EqADF <> 0 then Inc(Nb);
1459
    if Nb = 0
1460
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1461
      ClientDataSetIngredientsdNc.Clear
1462
    else // Moyenne des ?quations significatives
1463
    begin
1464
      dN := (EqCB + EqNDF + EqADF) / Nb;
1465
      ClientDataSetIngredientsdNc.Value := dN;
1466
    end;
1467
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1468
    then
1469
      EqCB := 0
1470
    else
1471
      EqCB := 77.9 + 77.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 87.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1472
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1473
   then
1474
      EqNDF := 0
1475
    else
1476
      EqNDF := 79.9 + 86.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 44.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1477
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1478
    then
1479
      EqADF := 0
1480
    else
1481
      EqADF := 78.3 + 78.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 83.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1482
    Nb := 0;
1483
    if EqCB <> 0 then Inc(Nb);
1484
    if EqNDF <> 0 then Inc(Nb);
1485
    if EqADF <> 0 then Inc(Nb);
1486
    if Nb = 0
1487
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1488
      ClientDataSetIngredientsdNt.Clear
1489
    else // Moyenne des ?quations significatives
1490
    begin
1491
      dN := (EqCB + EqNDF + EqADF) / Nb;
1492
      ClientDataSetIngredientsdNt.Value := dN;
1493
    end;
1494
  end;
1495
  // Acides amin?s
1496
  if RapMAT = 0
1497
  then // En l'absence de MAT, il n'y a pas d'acides amin?s
1498
  begin
1499
    // Teneurs
1500
    ClientDataSetIngredientsLys.Clear;
1501
    ClientDataSetIngredientsThr.Clear;
1502
    ClientDataSetIngredientsMet.Clear;
1503
    ClientDataSetIngredientsCys.Clear;
1504
    ClientDataSetIngredientsMetCys.Clear;
1505
    ClientDataSetIngredientsTrp.Clear;
1506
    ClientDataSetIngredientsIle.Clear;
1507
    ClientDataSetIngredientsVal.Clear;
1508
    ClientDataSetIngredientsLeu.Clear;
1509
    ClientDataSetIngredientsPhe.Clear;
1510
    ClientDataSetIngredientsTyr.Clear;
1511
    ClientDataSetIngredientsPheTyr.Clear;
1512
    ClientDataSetIngredientsHis.Clear;
1513
    ClientDataSetIngredientsArg.Clear;
1514
    ClientDataSetIngredientsAla.Clear;
1515
    ClientDataSetIngredientsAsp.Clear;
1516
    ClientDataSetIngredientsGlu.Clear;
1517
    ClientDataSetIngredientsGly.Clear;
1518
    ClientDataSetIngredientsSer.Clear;
1519
    ClientDataSetIngredientsPro.Clear;
1520
    // % MAT
1521
    ClientDataSetIngredientsLys_MAT.Clear;
1522
    ClientDataSetIngredientsThr_MAT.Clear;
1523
    ClientDataSetIngredientsMet_MAT.Clear;
1524
    ClientDataSetIngredientsCys_MAT.Clear;
1525
    ClientDataSetIngredientsMetCys_MAT.Clear;
1526
    ClientDataSetIngredientsTrp_MAT.Clear;
1527
    ClientDataSetIngredientsIle_MAT.Clear;
1528
    ClientDataSetIngredientsVal_MAT.Clear;
1529
    ClientDataSetIngredientsLeu_MAT.Clear;
1530
    ClientDataSetIngredientsPhe_MAT.Clear;
1531
    ClientDataSetIngredientsTyr_MAT.Clear;
1532
    ClientDataSetIngredientsPheTyr_MAT.Clear;
1533
    ClientDataSetIngredientsHis_MAT.Clear;
1534
    ClientDataSetIngredientsArg_MAT.Clear;
1535
    ClientDataSetIngredientsAla_MAT.Clear;
1536
    ClientDataSetIngredientsAsp_MAT.Clear;
1537
    ClientDataSetIngredientsGlu_MAT.Clear;
1538
    ClientDataSetIngredientsGly_MAT.Clear;
1539
    ClientDataSetIngredientsSer_MAT.Clear;
1540
    ClientDataSetIngredientsPro_MAT.Clear;
1541
    // Digestibilit?s
1542
    ClientDataSetIngredientsdLys.Clear;
1543
    ClientDataSetIngredientsdThr.Clear;
1544
    ClientDataSetIngredientsdMet.Clear;
1545
    ClientDataSetIngredientsdCys.Clear;
1546
    ClientDataSetIngredientsdMetCys.Clear;
1547
    ClientDataSetIngredientsdTrp.Clear;
1548
    ClientDataSetIngredientsdIle.Clear;
1549
    ClientDataSetIngredientsdVal.Clear;
1550
    ClientDataSetIngredientsdLeu.Clear;
1551
    ClientDataSetIngredientsdPhe.Clear;
1552
    ClientDataSetIngredientsdTyr.Clear;
1553
    ClientDataSetIngredientsdPheTyr.Clear;
1554
    ClientDataSetIngredientsdHis.Clear;
1555
    ClientDataSetIngredientsdArg.Clear;
1556
    ClientDataSetIngredientsdAla.Clear;
1557
    ClientDataSetIngredientsdAsp.Clear;
1558
    ClientDataSetIngredientsdGlu.Clear;
1559
    ClientDataSetIngredientsdGly.Clear;
1560
    ClientDataSetIngredientsdSer.Clear;
1561
    ClientDataSetIngredientsdPro.Clear;
1562
    // Teneurs digestibles
1563
    ClientDataSetIngredientsLysd.Clear;
1564
    ClientDataSetIngredientsThrd.Clear;
1565
    ClientDataSetIngredientsMetd.Clear;
1566
    ClientDataSetIngredientsCysd.Clear;
1567
    ClientDataSetIngredientsMetCysd.Clear;
1568
    ClientDataSetIngredientsTrpd.Clear;
1569
    ClientDataSetIngredientsIled.Clear;
1570
    ClientDataSetIngredientsVald.Clear;
1571
    ClientDataSetIngredientsLeud.Clear;
1572
    ClientDataSetIngredientsPhed.Clear;
1573
    ClientDataSetIngredientsTyrd.Clear;
1574
    ClientDataSetIngredientsPheTyrd.Clear;
1575
    ClientDataSetIngredientsHisd.Clear;
1576
    ClientDataSetIngredientsArgd.Clear;
1577
    ClientDataSetIngredientsAlad.Clear;
1578
    ClientDataSetIngredientsAspd.Clear;
1579
    ClientDataSetIngredientsGlud.Clear;
1580
    ClientDataSetIngredientsGlyd.Clear;
1581
    ClientDataSetIngredientsSerd.Clear;
1582
    ClientDataSetIngredientsProd.Clear;
1583
  end
1584
  else
1585
  begin
1586
    // Lys
1587
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Lys'])
1588
    then
1589
    begin
1590
      ClientDataSetIngredientsLys.Clear;
1591
      ClientDataSetIngredientsLys_MAT.Clear;
1592
      ClientDataSetIngredientsdLys.Clear;
1593
      ClientDataSetIngredientsLysd.Clear;
1594
    end
1595
    else
1596
    begin
1597
      ClientDataSetIngredientsLys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Lys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1598
      ClientDataSetIngredientsLys_MAT.Value := InputAA(ClientDataSetIngredientsLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1599
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dLys'])
1600
      then
1601
        ClientDataSetIngredientsdLys.Value := dLys * 100
1602
      else
1603
        ClientDataSetIngredientsdLys.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dLys']) * 100;
1604
      ClientDataSetIngredientsLysd.Value := ClientDataSetIngredientsdLys.Value * ClientDataSetIngredientsLys.Value / 100;
1605
    end;
1606
    // Thr
1607
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Thr'])
1608
    then
1609
    begin
1610
      ClientDataSetIngredientsThr.Clear;
1611
      ClientDataSetIngredientsThr_MAT.Clear;
1612
      ClientDataSetIngredientsdThr.Clear;
1613
      ClientDataSetIngredientsThrd.Clear;
1614
    end
1615
    else
1616
    begin
1617
      ClientDataSetIngredientsThr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Thr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1618
      ClientDataSetIngredientsThr_MAT.Value := InputAA(ClientDataSetIngredientsThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1619
      ClientDataSetIngredientsdThr.Value := dThr * 100;
1620
      ClientDataSetIngredientsThrd.Value := dThr * ClientDataSetIngredientsThr.Value;
1621
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dThr'])
1622
      then
1623
        ClientDataSetIngredientsdThr.Value := dThr * 100
1624
      else
1625
        ClientDataSetIngredientsdThr.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dThr']) * 100;
1626
      ClientDataSetIngredientsThrd.Value := ClientDataSetIngredientsdThr.Value * ClientDataSetIngredientsThr.Value / 100;
1627
    end;
1628
    // Met
1629
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Met'])
1630
    then
1631
    begin
1632
      ClientDataSetIngredientsMet.Clear;
1633
      ClientDataSetIngredientsMet_MAT.Clear;
1634
      ClientDataSetIngredientsdMet.Clear;
1635
      ClientDataSetIngredientsMetd.Clear;
1636
    end
1637
    else
1638
    begin
1639
      ClientDataSetIngredientsMet.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Met']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1640
      ClientDataSetIngredientsMet_MAT.Value := InputAA(ClientDataSetIngredientsMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1641
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dMet'])
1642
      then
1643
        ClientDataSetIngredientsdMet.Value := dMet * 100
1644
      else
1645
        ClientDataSetIngredientsdMet.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dMet']) * 100;
1646
      ClientDataSetIngredientsMetd.Value := ClientDataSetIngredientsdMet.Value * ClientDataSetIngredientsMet.Value / 100;
1647
    end;
1648
    // Cys
1649
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cys'])
1650
    then
1651
    begin
1652
      ClientDataSetIngredientsCys.Clear;
1653
      ClientDataSetIngredientsCys_MAT.Clear;
1654
      ClientDataSetIngredientsdCys.Clear;
1655
      ClientDataSetIngredientsCysd.Clear;
1656
    end
1657
    else
1658
    begin
1659
      ClientDataSetIngredientsCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1660
      ClientDataSetIngredientsCys_MAT.Value := InputAA(ClientDataSetIngredientsCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1661
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dCys'])
1662
      then
1663
        ClientDataSetIngredientsdCys.Value := dCys * 100
1664
      else
1665
        ClientDataSetIngredientsdCys.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dCys']) * 100;
1666
      ClientDataSetIngredientsCysd.Value := ClientDataSetIngredientsdCys.Value * ClientDataSetIngredientsCys.Value / 100;
1667
    end;
1668
    // Met + Cys
1669
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MetCys'])
1670
    then
1671
    begin
1672
      ClientDataSetIngredientsMetCys.Clear;
1673
      ClientDataSetIngredientsMetCys_MAT.Clear;
1674
      ClientDataSetIngredientsdMetCys.Clear;
1675
      ClientDataSetIngredientsMetCysd.Clear;
1676
    end
1677
    else
1678
    begin
1679
      ClientDataSetIngredientsMetCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MetCys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1680
      ClientDataSetIngredientsMetCys_MAT.Value := InputAA(ClientDataSetIngredientsMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1681
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dMetCys'])
1682
      then
1683
        ClientDataSetIngredientsdMetCys.Value := dMetCys * 100
1684
      else
1685
        ClientDataSetIngredientsdMetCys.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dMetCys']) * 100;
1686
      ClientDataSetIngredientsMetCysd.Value := ClientDataSetIngredientsdMetCys.Value * ClientDataSetIngredientsMetCys.Value / 100;
1687
    end;
1688
    // Trp
1689
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Trp'])
1690
    then
1691
    begin
1692
      ClientDataSetIngredientsTrp.Clear;
1693
      ClientDataSetIngredientsTrp_MAT.Clear;
1694
      ClientDataSetIngredientsdTrp.Clear;
1695
      ClientDataSetIngredientsTrpd.Clear;
1696
    end
1697
    else
1698
    begin
1699
      ClientDataSetIngredientsTrp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Trp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1700
      ClientDataSetIngredientsTrp_MAT.Value := InputAA(ClientDataSetIngredientsTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1701
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dTrp'])
1702
      then
1703
        ClientDataSetIngredientsdTrp.Value := dTrp * 100
1704
      else
1705
        ClientDataSetIngredientsdTrp.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dTrp']) * 100;
1706
      ClientDataSetIngredientsTrpd.Value := ClientDataSetIngredientsdTrp.Value * ClientDataSetIngredientsTrp.Value / 100;
1707
    end;
1708
    // Ile
1709
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ile'])
1710
    then
1711
    begin
1712
      ClientDataSetIngredientsIle.Clear;
1713
      ClientDataSetIngredientsIle_MAT.Clear;
1714
      ClientDataSetIngredientsdIle.Clear;
1715
      ClientDataSetIngredientsIled.Clear;
1716
    end
1717
    else
1718
    begin
1719
      ClientDataSetIngredientsIle.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ile']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1720
      ClientDataSetIngredientsIle_MAT.Value := InputAA(ClientDataSetIngredientsIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1721
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dIle'])
1722
      then
1723
        ClientDataSetIngredientsdIle.Value := dIle * 100
1724
      else
1725
        ClientDataSetIngredientsdIle.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dIle']) * 100;
1726
      ClientDataSetIngredientsIled.Value := ClientDataSetIngredientsdIle.Value * ClientDataSetIngredientsIle.Value / 100;
1727
    end;
1728
    // Val
1729
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Val'])
1730
    then
1731
    begin
1732
      ClientDataSetIngredientsVal.Clear;
1733
      ClientDataSetIngredientsVal_MAT.Clear;
1734
      ClientDataSetIngredientsdVal.Clear;
1735
      ClientDataSetIngredientsVald.Clear;
1736
    end
1737
    else
1738
    begin
1739
      ClientDataSetIngredientsVal.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Val']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1740
      ClientDataSetIngredientsVal_MAT.Value := InputAA(ClientDataSetIngredientsVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1741
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dVal'])
1742
      then
1743
        ClientDataSetIngredientsdVal.Value := dVal * 100
1744
      else
1745
        ClientDataSetIngredientsdVal.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dVal']) * 100;
1746
      ClientDataSetIngredientsVald.Value := ClientDataSetIngredientsdVal.Value * ClientDataSetIngredientsVal.Value / 100;
1747
    end;
1748
    // Leu
1749
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Leu'])
1750
    then
1751
    begin
1752
      ClientDataSetIngredientsLeu.Clear;
1753
      ClientDataSetIngredientsLeu_MAT.Clear;
1754
      ClientDataSetIngredientsdLeu.Clear;
1755
      ClientDataSetIngredientsLeud.Clear;
1756
    end
1757
    else
1758
    begin
1759
      ClientDataSetIngredientsLeu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Leu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1760
      ClientDataSetIngredientsLeu_MAT.Value := InputAA(ClientDataSetIngredientsLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1761
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dLeu'])
1762
      then
1763
        ClientDataSetIngredientsdLeu.Value := dLeu * 100
1764
      else
1765
        ClientDataSetIngredientsdLeu.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dLeu']) * 100;
1766
      ClientDataSetIngredientsLeud.Value := ClientDataSetIngredientsdLeu.Value * ClientDataSetIngredientsLeu.Value / 100;
1767
    end;
1768
    // Phe
1769
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Phe'])
1770
    then
1771
    begin
1772
      ClientDataSetIngredientsPhe.Clear;
1773
      ClientDataSetIngredientsPhe_MAT.Clear;
1774
      ClientDataSetIngredientsdPhe.Clear;
1775
      ClientDataSetIngredientsPhed.Clear;
1776
    end
1777
    else
1778
    begin
1779
      ClientDataSetIngredientsPhe.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Phe']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1780
      ClientDataSetIngredientsPhe_MAT.Value := InputAA(ClientDataSetIngredientsPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1781
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPhe'])
1782
      then
1783
        ClientDataSetIngredientsdPhe.Value := dPhe * 100
1784
      else
1785
        ClientDataSetIngredientsdPhe.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPhe']) * 100;
1786
      ClientDataSetIngredientsPhed.Value := ClientDataSetIngredientsdPhe.Value * ClientDataSetIngredientsPhe.Value / 100;
1787
    end;
1788
    // Tyr
1789
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Tyr'])
1790
    then
1791
    begin
1792
      ClientDataSetIngredientsTyr.Clear;
1793
      ClientDataSetIngredientsTyr_MAT.Clear;
1794
      ClientDataSetIngredientsdTyr.Clear;
1795
      ClientDataSetIngredientsTyrd.Clear;
1796
    end
1797
    else
1798
    begin
1799
      ClientDataSetIngredientsTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Tyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1800
      ClientDataSetIngredientsTyr_MAT.Value := InputAA(ClientDataSetIngredientsTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1801
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dTyr'])
1802
      then
1803
        ClientDataSetIngredientsdTyr.Value := dTyr * 100
1804
      else
1805
        ClientDataSetIngredientsdTyr.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dTyr']) * 100;
1806
      ClientDataSetIngredientsTyrd.Value := ClientDataSetIngredientsdTyr.Value * ClientDataSetIngredientsTyr.Value / 100;
1807
    end;
1808
    // Phe + Tyr
1809
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['PheTyr'])
1810
    then
1811
    begin
1812
      ClientDataSetIngredientsPheTyr.Clear;
1813
      ClientDataSetIngredientsPheTyr_MAT.Clear;
1814
      ClientDataSetIngredientsdPheTyr.Clear;
1815
      ClientDataSetIngredientsPheTyrd.Clear;
1816
    end
1817
    else
1818
    begin
1819
      ClientDataSetIngredientsPheTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['PheTyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1820
      ClientDataSetIngredientsPheTyr_MAT.Value := InputAA(ClientDataSetIngredientsPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1821
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPheTyr'])
1822
      then
1823
        ClientDataSetIngredientsdPheTyr.Value := dPheTyr * 100
1824
      else
1825
        ClientDataSetIngredientsdPheTyr.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPheTyr']) * 100;
1826
      ClientDataSetIngredientsPheTyrd.Value := ClientDataSetIngredientsdPheTyr.Value * ClientDataSetIngredientsPheTyr.Value / 100;
1827
    end;
1828
    // His
1829
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['His'])
1830
    then
1831
    begin
1832
      ClientDataSetIngredientsHis.Clear;
1833
      ClientDataSetIngredientsHis_MAT.Clear;
1834
      ClientDataSetIngredientsdHis.Clear;
1835
      ClientDataSetIngredientsHisd.Clear;
1836
    end
1837
    else
1838
    begin
1839
      ClientDataSetIngredientsHis.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['His']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1840
      ClientDataSetIngredientsHis_MAT.Value := InputAA(ClientDataSetIngredientsHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1841
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dHis'])
1842
      then
1843
        ClientDataSetIngredientsdHis.Value := dHis * 100
1844
      else
1845
        ClientDataSetIngredientsdHis.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dHis']) * 100;
1846
      ClientDataSetIngredientsHisd.Value := ClientDataSetIngredientsdHis.Value * ClientDataSetIngredientsHis.Value / 100;
1847
    end;
1848
    // Arg
1849
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Arg'])
1850
    then
1851
    begin
1852
      ClientDataSetIngredientsArg.Clear;
1853
      ClientDataSetIngredientsArg_MAT.Clear;
1854
      ClientDataSetIngredientsdArg.Clear;
1855
      ClientDataSetIngredientsArgd.Clear;
1856
    end
1857
    else
1858
    begin
1859
      ClientDataSetIngredientsArg.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Arg']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1860
      ClientDataSetIngredientsArg_MAT.Value := InputAA(ClientDataSetIngredientsArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1861
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dArg'])
1862
      then
1863
        ClientDataSetIngredientsdArg.Value := dArg * 100
1864
      else
1865
        ClientDataSetIngredientsdArg.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dArg']) * 100;
1866
      ClientDataSetIngredientsArgd.Value := ClientDataSetIngredientsdArg.Value * ClientDataSetIngredientsArg.Value / 100;
1867
    end;
1868
    // Ala
1869
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ala'])
1870
    then
1871
    begin
1872
      ClientDataSetIngredientsAla.Clear;
1873
      ClientDataSetIngredientsAla_MAT.Clear;
1874
      ClientDataSetIngredientsdAla.Clear;
1875
      ClientDataSetIngredientsAlad.Clear;
1876
    end
1877
    else
1878
    begin
1879
      ClientDataSetIngredientsAla.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ala']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1880
      ClientDataSetIngredientsAla_MAT.Value := InputAA(ClientDataSetIngredientsAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1881
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dAla'])
1882
      then
1883
        ClientDataSetIngredientsdAla.Value := dAla * 100
1884
      else
1885
        ClientDataSetIngredientsdAla.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dAla']) * 100;
1886
      ClientDataSetIngredientsAlad.Value := ClientDataSetIngredientsdAla.Value * ClientDataSetIngredientsAla.Value / 100;
1887
    end;
1888
    // Asp
1889
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Asp'])
1890
    then
1891
    begin
1892
      ClientDataSetIngredientsAsp.Clear;
1893
      ClientDataSetIngredientsAsp_MAT.Clear;
1894
      ClientDataSetIngredientsdAsp.Clear;
1895
      ClientDataSetIngredientsAspd.Clear;
1896
    end
1897
    else
1898
    begin
1899
      ClientDataSetIngredientsAsp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Asp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1900
      ClientDataSetIngredientsAsp_MAT.Value := InputAA(ClientDataSetIngredientsAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1901
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dAsp'])
1902
      then
1903
        ClientDataSetIngredientsdAsp.Value := dAsp * 100
1904
      else
1905
        ClientDataSetIngredientsdAsp.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dAsp']) * 100;
1906
      ClientDataSetIngredientsAspd.Value := ClientDataSetIngredientsdAsp.Value * ClientDataSetIngredientsAsp.Value / 100;
1907
    end;
1908
    // Glu
1909
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Glu'])
1910
    then
1911
    begin
1912
      ClientDataSetIngredientsGlu.Clear;
1913
      ClientDataSetIngredientsGlu_MAT.Clear;
1914
      ClientDataSetIngredientsdGlu.Clear;
1915
      ClientDataSetIngredientsGlud.Clear;
1916
    end
1917
    else
1918
    begin
1919
      ClientDataSetIngredientsGlu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Glu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1920
      ClientDataSetIngredientsGlu_MAT.Value := InputAA(ClientDataSetIngredientsGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1921
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dGlu'])
1922
      then
1923
        ClientDataSetIngredientsdGlu.Value := dGlu * 100
1924
      else
1925
        ClientDataSetIngredientsdGlu.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dGlu']) * 100;
1926
      ClientDataSetIngredientsGlud.Value := ClientDataSetIngredientsdGlu.Value * ClientDataSetIngredientsGlu.Value / 100;
1927
    end;
1928
    // Gly
1929
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Gly'])
1930
    then
1931
    begin
1932
      ClientDataSetIngredientsGly.Clear;
1933
      ClientDataSetIngredientsGly_MAT.Clear;
1934
      ClientDataSetIngredientsdGly.Clear;
1935
      ClientDataSetIngredientsGlyd.Clear;
1936
    end
1937
    else
1938
    begin
1939
      ClientDataSetIngredientsGly.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Gly']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1940
      ClientDataSetIngredientsGly_MAT.Value := InputAA(ClientDataSetIngredientsGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1941
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dGly'])
1942
      then
1943
        ClientDataSetIngredientsdGly.Value := dGly * 100
1944
      else
1945
        ClientDataSetIngredientsdGly.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dGly']) * 100;
1946
      ClientDataSetIngredientsGlyd.Value := ClientDataSetIngredientsdGly.Value * ClientDataSetIngredientsGly.Value / 100;
1947
    end;
1948
    // Ser
1949
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ser'])
1950
    then
1951
    begin
1952
      ClientDataSetIngredientsSer.Clear;
1953
      ClientDataSetIngredientsSer_MAT.Clear;
1954
      ClientDataSetIngredientsdSer.Clear;
1955
      ClientDataSetIngredientsSerd.Clear;
1956
    end
1957
    else
1958
    begin
1959
      ClientDataSetIngredientsSer.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ser']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1960
      ClientDataSetIngredientsSer_MAT.Value := InputAA(ClientDataSetIngredientsSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1961
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dSer'])
1962
      then
1963
        ClientDataSetIngredientsdSer.Value := dSer * 100
1964
      else
1965
        ClientDataSetIngredientsdSer.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dSer']) * 100;
1966
      ClientDataSetIngredientsSerd.Value := ClientDataSetIngredientsdSer.Value * ClientDataSetIngredientsSer.Value / 100;
1967
    end;
1968
    // Pro
1969
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Pro'])
1970
    then
1971
    begin
1972
      ClientDataSetIngredientsPro.Clear;
1973
      ClientDataSetIngredientsPro_MAT.Clear;
1974
      ClientDataSetIngredientsdPro.Clear;
1975
      ClientDataSetIngredientsProd.Clear;
1976
    end
1977
    else
1978
    begin
1979
      ClientDataSetIngredientsPro.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Pro']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1980
      ClientDataSetIngredientsPro_MAT.Value := InputAA(ClientDataSetIngredientsPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1981
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPro'])
1982
      then
1983
        ClientDataSetIngredientsdPro.Value := dPro * 100
1984
      else
1985
        ClientDataSetIngredientsdPro.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPro']) * 100;
1986
      ClientDataSetIngredientsProd.Value := ClientDataSetIngredientsdPro.Value * ClientDataSetIngredientsPro.Value / 100;
1987
    end;
1988
  end;
1989
  // Min?raux
1990
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
1991
  then
1992
    ClientDataSetIngredientsCa.Clear
1993
  else
1994
    ClientDataSetIngredientsCa.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ca']), RapMS, FormOptions.Expression, FormOptions.Minerals);
1995
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
1996
  then
1997
    ClientDataSetIngredientsP.Clear
1998
  else
1999
    ClientDataSetIngredientsP.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['P']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2000
  if ClientDataSetIngredientsP.Value = 0
2001
  then // En l'absence de P, il n'y a pas de dP
2002
  begin
2003
    ClientDataSetIngredientsdP.Clear;
2004
    ClientDataSetIngredientsdPphy.Clear;
2005
  end
2006
  else
2007
  begin
2008
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
2009
    then // Par d?faut dP = 20%
2010
      ClientDataSetIngredientsdP.Value := 20
2011
    else
2012
      ClientDataSetIngredientsdP.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dP']) * 100;
2013
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
2014
    then // Par d?faut dPphy = dP
2015
      ClientDataSetIngredientsdPphy.Value := ClientDataSetIngredientsdP.Value
2016
    else
2017
      ClientDataSetIngredientsdPphy.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPphy']) * 100;
2018
  end;
2019
  // Autres rapports
2020
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
2021
  then
2022
    ClientDataSetIngredientsLysd_ENc.Clear
2023
  else
2024
    if FormOptions.Energy = 0
2025
    then // g / MJ
2026
      if FormOptions.AA = 0
2027
      then // % (conversion)
2028
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value
2029
      else // g/kg
2030
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value
2031
    else // g / 1000 kcal
2032
      if FormOptions.AA = 0
2033
      then // % (conversion)
2034
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value * 1000
2035
      else // g/kg
2036
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value * 1000;
2037
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENt.IsNull or (ClientDataSetIngredientsENt.Value = 0)
2038
  then
2039
    ClientDataSetIngredientsLysd_ENt.Clear
2040
  else
2041
    if FormOptions.Energy = 0
2042
    then // g / MJ
2043
      if FormOptions.AA = 0
2044
      then // % (conversion)
2045
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value
2046
      else // g/kg
2047
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value
2048
    else // g / 1000 kcal
2049
      if FormOptions.AA = 0
2050
      then // % (conversion)
2051
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value * 1000
2052
      else // g/kg
2053
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value * 1000;
2054
end;
2055
2056
procedure TDataModuleDeclaration.CalcCopy;
2057
// Renseigner l'enregistrement courant de ClientDataSetIngredients
2058
// ? partir de l'enregistrement courant de TableIngredients
2059
// en tenant compte des unit?s configur?es
2060
var
2061
  Nb: Integer;
2062
  Bonus, EB, dE, EDc, EDt, EM, EM_ED, EN_EM, dN: Double;
2063
  CorrMAT, CorrMG, CorrMM, CorrCB, CorrNDF, CorrADF, DiffMAT, DiffMG, DiffAmidon: Double;
2064
begin
2065
  // Analyse proximale
2066
  RapMS := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MS']);
2067
  ClientDataSetIngredientsMS.Value := OutputProximal(RapMS, 1, 1, FormOptions.Proximal);
2068
  ClientDataSetIngredientsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
2069
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
2070
  then
2071
    if ClientDataSetInraAfzMM.IsNull
2072
    then
2073
      ClientDataSetIngredientsMM.Clear
2074
    else
2075
      ClientDataSetIngredientsMM.Value := OutputProximal(ClientDataSetInraAfzMM.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2076
  else
2077
    ClientDataSetIngredientsMM.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2078
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2079
  then
2080
    if ClientDataSetInraAfzMAT.IsNull
2081
    then
2082
      ClientDataSetIngredientsMAT.Clear
2083
    else
2084
    begin
2085
      RapMAT := ClientDataSetInraAfzMAT.Value;
2086
      ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
2087
    end
2088
  else
2089
  begin
2090
    RapMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']);
2091
    ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
2092
  end;
2093
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2094
  then
2095
    if ClientDataSetInraAfzMG.IsNull
2096
    then
2097
      ClientDataSetIngredientsMG.Clear
2098
    else
2099
      ClientDataSetIngredientsMG.Value := OutputProximal(ClientDataSetInraAfzMG.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2100
  else
2101
    ClientDataSetIngredientsMG.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2102
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2103
  then
2104
    if ClientDataSetInraAfzCB.IsNull
2105
    then
2106
      ClientDataSetIngredientsCB.Clear
2107
    else
2108
      ClientDataSetIngredientsCB.Value := OutputProximal(ClientDataSetInraAfzCB.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2109
  else
2110
    ClientDataSetIngredientsCB.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2111
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2112
  then
2113
    if ClientDataSetInraAfzNDF.IsNull
2114
    then
2115
      ClientDataSetIngredientsNDF.Clear
2116
    else
2117
      ClientDataSetIngredientsNDF.Value := OutputProximal(ClientDataSetInraAfzNDF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2118
  else
2119
    ClientDataSetIngredientsNDF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2120
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2121
  then
2122
    if ClientDataSetInraAfzADF.IsNull
2123
    then
2124
      ClientDataSetIngredientsADF.Clear
2125
    else
2126
      ClientDataSetIngredientsADF.Value := OutputProximal(ClientDataSetInraAfzADF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2127
  else
2128
    ClientDataSetIngredientsADF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2129
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
2130
  then
2131
    if ClientDataSetInraAfzADL.IsNull
2132
    then
2133
      ClientDataSetIngredientsADL.Clear
2134
    else
2135
      ClientDataSetIngredientsADL.Value := OutputProximal(ClientDataSetInraAfzADL.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2136
  else
2137
    ClientDataSetIngredientsADL.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADL']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2138
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
2139
  then
2140
    if ClientDataSetInraAfzAmidon.IsNull
2141
    then
2142
      ClientDataSetIngredientsAmidon.Clear
2143
    else
2144
      ClientDataSetIngredientsAmidon.Value := OutputProximal(ClientDataSetInraAfzAmidon.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2145
  else
2146
    ClientDataSetIngredientsAmidon.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2147
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
2148
  then
2149
    if ClientDataSetInraAfzSucres.IsNull
2150
    then
2151
      ClientDataSetIngredientsSucres.Clear
2152
    else
2153
      ClientDataSetIngredientsSucres.Value := OutputProximal(ClientDataSetInraAfzSucres.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2154
  else
2155
    ClientDataSetIngredientsSucres.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2156
  // Energie -> Valeurs calcul?es
2157
  EB := ClientDataSetInraAfzEB.Value;
2158
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2159
  then
2160
    CorrMAT := 0
2161
  else
2162
    CorrMAT := CoefMAT * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value);
2163
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2164
  then
2165
    CorrMG := 0
2166
  else
2167
    CorrMG := CoefMG * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - ClientDataSetInraAfzMG.Value);
2168
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
2169
  then
2170
    CorrMM := 0
2171
  else
2172
    CorrMM := CoefMM * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - ClientDataSetInraAfzMM.Value);
2173
  // Correction : somme des corrections (born?e ? 0)
2174
  EB := Max(0, EB + CorrMAT + CorrMG + CorrMM);
2175
  ClientDataSetIngredientsEB.Value := OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy);
2176
  Bonus := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Bonus']) * 100;
2177
  ClientDataSetIngredientsBonus.Value := Bonus;
2178
  dE := ClientDataSetInraAfzdEc.Value * 100 + Bonus;
2179
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2180
  then
2181
    CorrCB := 0
2182
  else
2183
    CorrCB := ClientDataSetInraAfzCoefCB.Value * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - ClientDataSetInraAfzCB.Value) * 100;
2184
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2185
  then
2186
    CorrNDF := 0
2187
  else
2188
    CorrNDF := ClientDataSetInraAfzCoefNDF.Value * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - ClientDataSetInraAfzNDF.Value) * 100;
2189
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2190
  then
2191
    CorrADF := 0
2192
  else
2193
    CorrADF := ClientDataSetInraAfzCoefADF.Value * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - ClientDataSetInraAfzADF.Value) * 100;
2194
  Nb := 0;
2195
  if CorrCB <> 0 then Inc(Nb);
2196
  if CorrNDF <> 0 then Inc(Nb);
2197
  if CorrADF <> 0 then Inc(Nb);
2198
  if Nb > 0
2199
  then // Correction : moyenne des ?quations significatives (born?e ? 0)
2200
    dE := Max(0, dE + (CorrCB + CorrNDF + CorrADF) / Nb);
2201
  ClientDataSetIngredientsdEc.Value := dE;
2202
  EDc := EB * dE / 100;
2203
  ClientDataSetIngredientsEDc.Value := OutputEnergy(EDc, RapMS, FormOptions.Expression, FormOptions.Energy);
2204
  if EDc = 0
2205
  then // Division par 0
2206
  begin
2207
    ClientDataSetIngredientsEMc_EDc.Value := 0;
2208
    ClientDataSetIngredientsEMc.Value := 0;
2209
    EM := 0;
2210
  end
2211
  else
2212
  begin
2213
    EM_ED := ClientDataSetInraAfzEMc_EDc.Value;
2214
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2215
    then
2216
      DiffMAT := 0
2217
    else
2218
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2219
    if DiffMAT <> 0
2220
    then // Correction : variation de l'azote
2221
      EM_ED := EM_ED - 31.0 * 0.4 * DiffMAT / 6.25 / EDc;
2222
    ClientDataSetIngredientsEMc_EDc.Value := EM_ED * 100;
2223
    EM := EDc * EM_ED;
2224
    ClientDataSetIngredientsEMc.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2225
  end;
2226
  if EM = 0
2227
  then // Division par 0
2228
  begin
2229
    ClientDataSetIngredientsENc_EMc.Value := 0;
2230
    ClientDataSetIngredientsENc.Value := 0;
2231
  end
2232
  else
2233
  begin
2234
    EN_EM := ClientDataSetInraAfzENc_EMc.Value;
2235
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2236
    then
2237
      DiffMAT := 0
2238
    else
2239
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2240
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2241
    then
2242
      DiffMG := 0
2243
    else
2244
      DiffMG := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - ClientDataSetInraAfzMG.Value;
2245
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
2246
    then
2247
      DiffAmidon := 0
2248
    else
2249
      DiffAmidon := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - ClientDataSetInraAfzAmidon.Value;
2250
    if (DiffMAT <> 0) or (DiffMG <> 0) or (DiffAmidon <> 0)
2251
    then // Correction : variation MAT et/ou MG et/ou Amidon
2252
      EN_EM := EN_EM + (-2.8 * DiffMAT + 5.5 * DiffMG + 1.5 * DiffAmidon) / EM;
2253
    ClientDataSetIngredientsENc_EMc.Value := EN_EM * 100;
2254
    ClientDataSetIngredientsENc.Value := OutputEnergy(EM * EN_EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2255
  end;
2256
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
2257
  then
2258
    EDt := EDc + ClientDataSetInraAfza.Value * CALORIE * (1 - ClientDataSetInraAfzMM.Value) * (1 - ClientDataSetInraAfzb.Value * dE / 100)
2259
  else
2260
    EDt := EDc + ClientDataSetInraAfza.Value * CALORIE * (1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM'])) * (1 - ClientDataSetInraAfzb.Value * dE / 100);
2261
  ClientDataSetIngredientsEDt.Value := OutputEnergy(EDt, RapMS, FormOptions.Expression, FormOptions.Energy);
2262
  if EDc = 0
2263
  then // Division par 0
2264
    ClientDataSetIngredientsEDt_EDc.Value := 100
2265
  else
2266
    ClientDataSetIngredientsEDt_EDc.Value := EDt / EDc * 100;
2267
  if EDt = 0
2268
  then // Division par 0
2269
  begin
2270
    ClientDataSetIngredientsEMt_EDt.Value := 0;
2271
    ClientDataSetIngredientsEMt.Value := 0;
2272
    EM := 0;
2273
  end
2274
  else
2275
  begin
2276
    EM_ED := ClientDataSetInraAfzEMt_EDt.Value;
2277
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2278
    then
2279
      DiffMAT := 0
2280
    else
2281
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2282
    if DiffMAT <> 0
2283
    then // Correction : variation de l'azote
2284
      EM_ED := EM_ED - 31.0 * 0.4 * DiffMAT / 6.25 / EDt;
2285
    ClientDataSetIngredientsEMt_EDt.Value := EM_ED * 100;
2286
    EM := EDt * EM_ED;
2287
    ClientDataSetIngredientsEMt.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2288
  end;
2289
  if EM = 0
2290
  then // Division par 0
2291
  begin
2292
    ClientDataSetIngredientsENt_EMt.Value := 0;
2293
    ClientDataSetIngredientsENt.Value := 0;
2294
  end
2295
  else
2296
  begin
2297
    EN_EM := ClientDataSetInraAfzENt_EMt.Value;
2298
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2299
    then
2300
      DiffMAT := 0
2301
    else
2302
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2303
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2304
    then
2305
      DiffMG := 0
2306
    else
2307
      DiffMG := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - ClientDataSetInraAfzMG.Value;
2308
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
2309
    then
2310
      DiffAmidon := 0
2311
    else
2312
      DiffAmidon := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - ClientDataSetInraAfzAmidon.Value;
2313
    if (DiffMAT <> 0) or (DiffMG <> 0) or (DiffAmidon <> 0)
2314
    then // Correction : variation MAT et/ou MG et/ou Amidon
2315
      EN_EM := EN_EM + (-2.8 * DiffMAT + 5.5 * DiffMG + 1.5 * DiffAmidon) / EM;
2316
    ClientDataSetIngredientsENt_EMt.Value := EN_EM * 100;
2317
    ClientDataSetIngredientsENt.Value := OutputEnergy(EM * EN_EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2318
  end;
2319
  if ClientDataSetIngredientsEB.Value = 0
2320
  then
2321
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsdEc.Value
2322
  else
2323
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsEDt.Value / ClientDataSetIngredientsEB.Value * 100;
2324
  if ClientDataSetIngredientsEMc.Value = 0
2325
  then
2326
    ClientDataSetIngredientsEMt_EMc.Value := 100
2327
  else
2328
    ClientDataSetIngredientsEMt_EMc.Value := ClientDataSetIngredientsEMt.Value / ClientDataSetIngredientsEMc.Value * 100;
2329
  if ClientDataSetIngredientsENc.Value = 0
2330
  then
2331
    ClientDataSetIngredientsENt_ENc.Value := 100
2332
  else
2333
    ClientDataSetIngredientsENt_ENc.Value := ClientDataSetIngredientsENt.Value / ClientDataSetIngredientsENc.Value * 100;
2334
  // Digestibilit? f?cale de l'azote
2335
  if ClientDataSetInraAfzdNc.IsNull
2336
  then
2337
    ClientDataSetIngredientsdNc.Clear
2338
  else
2339
  begin
2340
    dN := ClientDataSetInraAfzdNc.Value * 100;
2341
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2342
    then
2343
      DiffMAT := 0
2344
    else
2345
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2346
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2347
    then
2348
      CorrCB := 0
2349
    else
2350
      CorrCB := 69.0 * DiffMAT - 122.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - ClientDataSetInraAfzCB.Value);
2351
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2352
    then
2353
      CorrNDF := 0
2354
    else
2355
      CorrNDF := 79.0 * DiffMAT - 69.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - ClientDataSetInraAfzNDF.Value);
2356
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2357
    then
2358
      CorrADF := 0
2359
    else
2360
      CorrADF := 70.0 * DiffMAT - 116.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - ClientDataSetInraAfzADF.Value);
2361
    Nb := 0;
2362
    if CorrCB <> 0 then Inc(Nb);
2363
    if CorrNDF <> 0 then Inc(Nb);
2364
    if CorrADF <> 0 then Inc(Nb);
2365
    if Nb > 0
2366
    then // Correction : moyenne des ?quations significatives
2367
      dN := dN + (CorrCB + CorrNDF + CorrADF) / Nb;
2368
    ClientDataSetIngredientsdNc.Value := dN;
2369
  end;
2370
  if ClientDataSetInraAfzdNt.IsNull
2371
  then
2372
    ClientDataSetIngredientsdNt.Clear
2373
  else
2374
  begin
2375
    dN := ClientDataSetInraAfzdNt.Value * 100;
2376
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2377
    then
2378
      DiffMAT := 0
2379
    else
2380
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2381
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2382
    then
2383
      CorrCB := 0
2384
    else
2385
      CorrCB := 77.0 * DiffMAT - 87.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - ClientDataSetInraAfzCB.Value);
2386
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2387
    then
2388
      CorrNDF := 0
2389
    else
2390
      CorrNDF := 86.0 * DiffMAT - 44.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - ClientDataSetInraAfzNDF.Value);
2391
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2392
    then
2393
      CorrADF := 0
2394
    else
2395
      CorrADF := 78.0 * DiffMAT - 83.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - ClientDataSetInraAfzADF.Value);
2396
    Nb := 0;
2397
    if CorrCB <> 0 then Inc(Nb);
2398
    if CorrNDF <> 0 then Inc(Nb);
2399
    if CorrADF <> 0 then Inc(Nb);
2400
    if Nb > 0
2401
    then // Correction : moyenne des ?quations significatives
2402
      dN := dN + (CorrCB + CorrNDF + CorrADF) / Nb;
2403
    ClientDataSetIngredientsdNt.Value := dN;
2404
  end;
2405
  // Acides amin?s
2406
  if RapMAT = 0
2407
  then // En l'absence de MAT, il n'y a pas d'acides amin?s
2408
  begin
2409
    // Teneurs
2410
    ClientDataSetIngredientsLys.Clear;
2411
    ClientDataSetIngredientsThr.Clear;
2412
    ClientDataSetIngredientsMet.Clear;
2413
    ClientDataSetIngredientsCys.Clear;
2414
    ClientDataSetIngredientsMetCys.Clear;
2415
    ClientDataSetIngredientsTrp.Clear;
2416
    ClientDataSetIngredientsIle.Clear;
2417
    ClientDataSetIngredientsVal.Clear;
2418
    ClientDataSetIngredientsLeu.Clear;
2419
    ClientDataSetIngredientsPhe.Clear;
2420
    ClientDataSetIngredientsTyr.Clear;
2421
    ClientDataSetIngredientsPheTyr.Clear;
2422
    ClientDataSetIngredientsHis.Clear;
2423
    ClientDataSetIngredientsArg.Clear;
2424
    ClientDataSetIngredientsAla.Clear;
2425
    ClientDataSetIngredientsAsp.Clear;
2426
    ClientDataSetIngredientsGlu.Clear;
2427
    ClientDataSetIngredientsGly.Clear;
2428
    ClientDataSetIngredientsSer.Clear;
2429
    ClientDataSetIngredientsPro.Clear;
2430
    // % MAT
2431
    ClientDataSetIngredientsLys_MAT.Clear;
2432
    ClientDataSetIngredientsThr_MAT.Clear;
2433
    ClientDataSetIngredientsMet_MAT.Clear;
2434
    ClientDataSetIngredientsCys_MAT.Clear;
2435
    ClientDataSetIngredientsMetCys_MAT.Clear;
2436
    ClientDataSetIngredientsTrp_MAT.Clear;
2437
    ClientDataSetIngredientsIle_MAT.Clear;
2438
    ClientDataSetIngredientsVal_MAT.Clear;
2439
    ClientDataSetIngredientsLeu_MAT.Clear;
2440
    ClientDataSetIngredientsPhe_MAT.Clear;
2441
    ClientDataSetIngredientsTyr_MAT.Clear;
2442
    ClientDataSetIngredientsPheTyr_MAT.Clear;
2443
    ClientDataSetIngredientsHis_MAT.Clear;
2444
    ClientDataSetIngredientsArg_MAT.Clear;
2445
    ClientDataSetIngredientsAla_MAT.Clear;
2446
    ClientDataSetIngredientsAsp_MAT.Clear;
2447
    ClientDataSetIngredientsGlu_MAT.Clear;
2448
    ClientDataSetIngredientsGly_MAT.Clear;
2449
    ClientDataSetIngredientsSer_MAT.Clear;
2450
    ClientDataSetIngredientsPro_MAT.Clear;
2451
    // Digestibilit?s
2452
    ClientDataSetIngredientsdLys.Clear;
2453
    ClientDataSetIngredientsdThr.Clear;
2454
    ClientDataSetIngredientsdMet.Clear;
2455
    ClientDataSetIngredientsdCys.Clear;
2456
    ClientDataSetIngredientsdMetCys.Clear;
2457
    ClientDataSetIngredientsdTrp.Clear;
2458
    ClientDataSetIngredientsdIle.Clear;
2459
    ClientDataSetIngredientsdVal.Clear;
2460
    ClientDataSetIngredientsdLeu.Clear;
2461
    ClientDataSetIngredientsdPhe.Clear;
2462
    ClientDataSetIngredientsdTyr.Clear;
2463
    ClientDataSetIngredientsdPheTyr.Clear;
2464
    ClientDataSetIngredientsdHis.Clear;
2465
    ClientDataSetIngredientsdArg.Clear;
2466
    ClientDataSetIngredientsdAla.Clear;
2467
    ClientDataSetIngredientsdAsp.Clear;
2468
    ClientDataSetIngredientsdGlu.Clear;
2469
    ClientDataSetIngredientsdGly.Clear;
2470
    ClientDataSetIngredientsdSer.Clear;
2471
    ClientDataSetIngredientsdPro.Clear;
2472
    // Teneurs digestibles
2473
    ClientDataSetIngredientsLysd.Clear;
2474
    ClientDataSetIngredientsThrd.Clear;
2475
    ClientDataSetIngredientsMetd.Clear;
2476
    ClientDataSetIngredientsCysd.Clear;
2477
    ClientDataSetIngredientsMetCysd.Clear;
2478
    ClientDataSetIngredientsTrpd.Clear;
2479
    ClientDataSetIngredientsIled.Clear;
2480
    ClientDataSetIngredientsVald.Clear;
2481
    ClientDataSetIngredientsLeud.Clear;
2482
    ClientDataSetIngredientsPhed.Clear;
2483
    ClientDataSetIngredientsTyrd.Clear;
2484
    ClientDataSetIngredientsPheTyrd.Clear;
2485
    ClientDataSetIngredientsHisd.Clear;
2486
    ClientDataSetIngredientsArgd.Clear;
2487
    ClientDataSetIngredientsAlad.Clear;
2488
    ClientDataSetIngredientsAspd.Clear;
2489
    ClientDataSetIngredientsGlud.Clear;
2490
    ClientDataSetIngredientsGlyd.Clear;
2491
    ClientDataSetIngredientsSerd.Clear;
2492
    ClientDataSetIngredientsProd.Clear;
2493
  end
2494
  else
2495
  begin
2496
    // Lys
2497
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Lys'])
2498
    and ClientDataSetInraAfzLys.IsNull
2499
    then
2500
    begin
2501
      ClientDataSetIngredientsLys.Clear;
2502
      ClientDataSetIngredientsLys_MAT.Clear;
2503
      ClientDataSetIngredientsdLys.Clear;
2504
      ClientDataSetIngredientsLysd.Clear;
2505
    end
2506
    else
2507
    begin
2508
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Lys'])
2509
      then
2510
        ClientDataSetIngredientsLys.Value := OutputAA(ClientDataSetInraAfzLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2511
      else
2512
        ClientDataSetIngredientsLys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Lys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2513
      ClientDataSetIngredientsLys_MAT.Value := InputAA(ClientDataSetIngredientsLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2514
      if ClientDataSetInraAfzdLys.IsNull
2515
      then
2516
        ClientDataSetIngredientsdLys.Value := dLys * 100
2517
      else
2518
        ClientDataSetIngredientsdLys.Value := ClientDataSetInraAfzdLys.Value * 100;
2519
      ClientDataSetIngredientsLysd.Value := ClientDataSetIngredientsdLys.Value / 100 * ClientDataSetIngredientsLys.Value;
2520
    end;
2521
    // Thr
2522
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Thr'])
2523
    and ClientDataSetInraAfzThr.IsNull
2524
    then
2525
    begin
2526
      ClientDataSetIngredientsThr.Clear;
2527
      ClientDataSetIngredientsThr_MAT.Clear;
2528
      ClientDataSetIngredientsdThr.Clear;
2529
      ClientDataSetIngredientsThrd.Clear;
2530
    end
2531
    else
2532
    begin
2533
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Thr'])
2534
      then
2535
        ClientDataSetIngredientsThr.Value := OutputAA(ClientDataSetInraAfzThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2536
      else
2537
        ClientDataSetIngredientsThr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Thr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2538
      ClientDataSetIngredientsThr_MAT.Value := InputAA(ClientDataSetIngredientsThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2539
      if ClientDataSetInraAfzdThr.IsNull
2540
      then
2541
        ClientDataSetIngredientsdThr.Value := dThr * 100
2542
      else
2543
        ClientDataSetIngredientsdThr.Value := ClientDataSetInraAfzdThr.Value * 100;
2544
      ClientDataSetIngredientsThrd.Value := ClientDataSetIngredientsdThr.Value / 100 * ClientDataSetIngredientsThr.Value;
2545
    end;
2546
    // Met
2547
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Met'])
2548
    and ClientDataSetInraAfzMet.IsNull
2549
    then
2550
    begin
2551
      ClientDataSetIngredientsMet.Clear;
2552
      ClientDataSetIngredientsMet_MAT.Clear;
2553
      ClientDataSetIngredientsdMet.Clear;
2554
      ClientDataSetIngredientsMetd.Clear;
2555
    end
2556
    else
2557
    begin
2558
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Met'])
2559
      then
2560
        ClientDataSetIngredientsMet.Value := OutputAA(ClientDataSetInraAfzMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2561
      else
2562
        ClientDataSetIngredientsMet.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Met']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2563
      ClientDataSetIngredientsMet_MAT.Value := InputAA(ClientDataSetIngredientsMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2564
      if ClientDataSetInraAfzdMet.IsNull
2565
      then
2566
        ClientDataSetIngredientsdMet.Value := dMet * 100
2567
      else
2568
        ClientDataSetIngredientsdMet.Value := ClientDataSetInraAfzdMet.Value * 100;
2569
      ClientDataSetIngredientsMetd.Value := ClientDataSetIngredientsdMet.Value / 100 * ClientDataSetIngredientsMet.Value;
2570
    end;
2571
    // Cys
2572
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cys'])
2573
    and ClientDataSetInraAfzCys.IsNull
2574
    then
2575
    begin
2576
      ClientDataSetIngredientsCys.Clear;
2577
      ClientDataSetIngredientsCys_MAT.Clear;
2578
      ClientDataSetIngredientsdCys.Clear;
2579
      ClientDataSetIngredientsCysd.Clear;
2580
    end
2581
    else
2582
    begin
2583
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cys'])
2584
      then
2585
        ClientDataSetIngredientsCys.Value := OutputAA(ClientDataSetInraAfzCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2586
      else
2587
        ClientDataSetIngredientsCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2588
      ClientDataSetIngredientsCys_MAT.Value := InputAA(ClientDataSetIngredientsCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2589
      if ClientDataSetInraAfzdCys.IsNull
2590
      then
2591
        ClientDataSetIngredientsdCys.Value := dCys * 100
2592
      else
2593
        ClientDataSetIngredientsdCys.Value := ClientDataSetInraAfzdCys.Value * 100;
2594
      ClientDataSetIngredientsCysd.Value := ClientDataSetIngredientsdCys.Value / 100 * ClientDataSetIngredientsCys.Value;
2595
    end;
2596
    // Met + Cys
2597
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MetCys'])
2598
    and ClientDataSetInraAfzMetCys.IsNull
2599
    then
2600
    begin
2601
      ClientDataSetIngredientsMetCys.Clear;
2602
      ClientDataSetIngredientsMetCys_MAT.Clear;
2603
      ClientDataSetIngredientsdMetCys.Clear;
2604
      ClientDataSetIngredientsMetCysd.Clear;
2605
    end
2606
    else
2607
    begin
2608
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MetCys'])
2609
      then
2610
        ClientDataSetIngredientsMetCys.Value := OutputAA(ClientDataSetInraAfzMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2611
      else
2612
        ClientDataSetIngredientsMetCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MetCys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2613
      ClientDataSetIngredientsMetCys_MAT.Value := InputAA(ClientDataSetIngredientsMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2614
      if ClientDataSetInraAfzdMetCys.IsNull
2615
      then
2616
        ClientDataSetIngredientsdMetCys.Value := dMetCys * 100
2617
      else
2618
        ClientDataSetIngredientsdMetCys.Value := ClientDataSetInraAfzdMetCys.Value * 100;
2619
      ClientDataSetIngredientsMetCysd.Value := ClientDataSetIngredientsdMetCys.Value / 100 * ClientDataSetIngredientsMetCys.Value;
2620
    end;
2621
    // Trp
2622
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Trp'])
2623
    and ClientDataSetInraAfzTrp.IsNull
2624
    then
2625
    begin
2626
      ClientDataSetIngredientsTrp.Clear;
2627
      ClientDataSetIngredientsTrp_MAT.Clear;
2628
      ClientDataSetIngredientsdTrp.Clear;
2629
      ClientDataSetIngredientsTrpd.Clear;
2630
    end
2631
    else
2632
    begin
2633
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Trp'])
2634
      then
2635
        ClientDataSetIngredientsTrp.Value := OutputAA(ClientDataSetInraAfzTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2636
      else
2637
        ClientDataSetIngredientsTrp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Trp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2638
      ClientDataSetIngredientsTrp_MAT.Value := InputAA(ClientDataSetIngredientsTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2639
      if ClientDataSetInraAfzdTrp.IsNull
2640
      then
2641
        ClientDataSetIngredientsdTrp.Value := dTrp * 100
2642
      else
2643
        ClientDataSetIngredientsdTrp.Value := ClientDataSetInraAfzdTrp.Value * 100;
2644
      ClientDataSetIngredientsTrpd.Value := ClientDataSetIngredientsdTrp.Value / 100 * ClientDataSetIngredientsTrp.Value;
2645
    end;
2646
    // Ile
2647
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ile'])
2648
    and ClientDataSetInraAfzIle.IsNull
2649
    then
2650
    begin
2651
      ClientDataSetIngredientsIle.Clear;
2652
      ClientDataSetIngredientsIle_MAT.Clear;
2653
      ClientDataSetIngredientsdIle.Clear;
2654
      ClientDataSetIngredientsIled.Clear;
2655
    end
2656
    else
2657
    begin
2658
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ile'])
2659
      then
2660
        ClientDataSetIngredientsIle.Value := OutputAA(ClientDataSetInraAfzIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2661
      else
2662
        ClientDataSetIngredientsIle.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ile']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2663
      ClientDataSetIngredientsIle_MAT.Value := InputAA(ClientDataSetIngredientsIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2664
      if ClientDataSetInraAfzdIle.IsNull
2665
      then
2666
        ClientDataSetIngredientsdIle.Value := dIle * 100
2667
      else
2668
        ClientDataSetIngredientsdIle.Value := ClientDataSetInraAfzdIle.Value * 100;
2669
      ClientDataSetIngredientsIled.Value := ClientDataSetIngredientsdIle.Value / 100 * ClientDataSetIngredientsIle.Value;
2670
    end;
2671
    // Val
2672
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Val'])
2673
    and ClientDataSetInraAfzVal.IsNull
2674
    then
2675
    begin
2676
      ClientDataSetIngredientsVal.Clear;
2677
      ClientDataSetIngredientsVal_MAT.Clear;
2678
      ClientDataSetIngredientsdVal.Clear;
2679
      ClientDataSetIngredientsVald.Clear;
2680
    end
2681
    else
2682
    begin
2683
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Val'])
2684
      then
2685
        ClientDataSetIngredientsVal.Value := OutputAA(ClientDataSetInraAfzVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2686
      else
2687
        ClientDataSetIngredientsVal.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Val']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2688
      ClientDataSetIngredientsVal_MAT.Value := InputAA(ClientDataSetIngredientsVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2689
      if ClientDataSetInraAfzdVal.IsNull
2690
      then
2691
        ClientDataSetIngredientsdVal.Value := dVal * 100
2692
      else
2693
        ClientDataSetIngredientsdVal.Value := ClientDataSetInraAfzdVal.Value * 100;
2694
      ClientDataSetIngredientsVald.Value := ClientDataSetIngredientsdVal.Value / 100 * ClientDataSetIngredientsVal.Value;
2695
    end;
2696
    // Leu
2697
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Leu'])
2698
    and ClientDataSetInraAfzLeu.IsNull
2699
    then
2700
    begin
2701
      ClientDataSetIngredientsLeu.Clear;
2702
      ClientDataSetIngredientsLeu_MAT.Clear;
2703
      ClientDataSetIngredientsdLeu.Clear;
2704
      ClientDataSetIngredientsLeud.Clear;
2705
    end
2706
    else
2707
    begin
2708
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Leu'])
2709
      then
2710
        ClientDataSetIngredientsLeu.Value := OutputAA(ClientDataSetInraAfzLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2711
      else
2712
        ClientDataSetIngredientsLeu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Leu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2713
      ClientDataSetIngredientsLeu_MAT.Value := InputAA(ClientDataSetIngredientsLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2714
      if ClientDataSetInraAfzdLeu.IsNull
2715
      then
2716
        ClientDataSetIngredientsdLeu.Value := dLeu * 100
2717
      else
2718
        ClientDataSetIngredientsdLeu.Value := ClientDataSetInraAfzdLeu.Value * 100;
2719
      ClientDataSetIngredientsLeud.Value := ClientDataSetIngredientsdLeu.Value / 100 * ClientDataSetIngredientsLeu.Value;
2720
    end;
2721
    // Phe
2722
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Phe'])
2723
    and ClientDataSetInraAfzPhe.IsNull
2724
    then
2725
    begin
2726
      ClientDataSetIngredientsPhe.Clear;
2727
      ClientDataSetIngredientsPhe_MAT.Clear;
2728
      ClientDataSetIngredientsdPhe.Clear;
2729
      ClientDataSetIngredientsPhed.Clear;
2730
    end
2731
    else
2732
    begin
2733
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Phe'])
2734
      then
2735
        ClientDataSetIngredientsPhe.Value := OutputAA(ClientDataSetInraAfzPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2736
      else
2737
        ClientDataSetIngredientsPhe.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Phe']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2738
      ClientDataSetIngredientsPhe_MAT.Value := InputAA(ClientDataSetIngredientsPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2739
      if ClientDataSetInraAfzdPhe.IsNull
2740
      then
2741
        ClientDataSetIngredientsdPhe.Value := dPhe * 100
2742
      else
2743
        ClientDataSetIngredientsdPhe.Value := ClientDataSetInraAfzdPhe.Value * 100;
2744
      ClientDataSetIngredientsPhed.Value := ClientDataSetIngredientsdPhe.Value / 100 * ClientDataSetIngredientsPhe.Value;
2745
    end;
2746
    // Tyr
2747
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Tyr'])
2748
    and ClientDataSetInraAfzTyr.IsNull
2749
    then
2750
    begin
2751
      ClientDataSetIngredientsTyr.Clear;
2752
      ClientDataSetIngredientsTyr_MAT.Clear;
2753
      ClientDataSetIngredientsdTyr.Clear;
2754
      ClientDataSetIngredientsTyrd.Clear;
2755
    end
2756
    else
2757
    begin
2758
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Tyr'])
2759
      then
2760
        ClientDataSetIngredientsTyr.Value := OutputAA(ClientDataSetInraAfzTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2761
      else
2762
        ClientDataSetIngredientsTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Tyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2763
      ClientDataSetIngredientsTyr_MAT.Value := InputAA(ClientDataSetIngredientsTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2764
      if ClientDataSetInraAfzdTyr.IsNull
2765
      then
2766
        ClientDataSetIngredientsdTyr.Value := dTyr * 100
2767
      else
2768
        ClientDataSetIngredientsdTyr.Value := ClientDataSetInraAfzdTyr.Value * 100;
2769
      ClientDataSetIngredientsTyrd.Value := ClientDataSetIngredientsdTyr.Value / 100 * ClientDataSetIngredientsTyr.Value;
2770
    end;
2771
    // Phe + Tyr
2772
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['PheTyr'])
2773
    and ClientDataSetInraAfzPheTyr.IsNull
2774
    then
2775
    begin
2776
      ClientDataSetIngredientsPheTyr.Clear;
2777
      ClientDataSetIngredientsPheTyr_MAT.Clear;
2778
      ClientDataSetIngredientsdPheTyr.Clear;
2779
      ClientDataSetIngredientsPheTyrd.Clear;
2780
    end
2781
    else
2782
    begin
2783
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['PheTyr'])
2784
      then
2785
        ClientDataSetIngredientsPheTyr.Value := OutputAA(ClientDataSetInraAfzPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2786
      else
2787
        ClientDataSetIngredientsPheTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['PheTyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2788
      ClientDataSetIngredientsPheTyr_MAT.Value := InputAA(ClientDataSetIngredientsPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2789
      if ClientDataSetInraAfzdPheTyr.IsNull
2790
      then
2791
        ClientDataSetIngredientsdPheTyr.Value := dPheTyr * 100
2792
      else
2793
        ClientDataSetIngredientsdPheTyr.Value := ClientDataSetInraAfzdPheTyr.Value * 100;
2794
      ClientDataSetIngredientsPheTyrd.Value := ClientDataSetIngredientsdPheTyr.Value / 100 * ClientDataSetIngredientsPheTyr.Value;
2795
    end;
2796
    // His
2797
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['His'])
2798
    and ClientDataSetInraAfzHis.IsNull
2799
    then
2800
    begin
2801
      ClientDataSetIngredientsHis.Clear;
2802
      ClientDataSetIngredientsHis_MAT.Clear;
2803
      ClientDataSetIngredientsdHis.Clear;
2804
      ClientDataSetIngredientsHisd.Clear;
2805
    end
2806
    else
2807
    begin
2808
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['His'])
2809
      then
2810
        ClientDataSetIngredientsHis.Value := OutputAA(ClientDataSetInraAfzHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2811
      else
2812
        ClientDataSetIngredientsHis.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['His']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2813
      ClientDataSetIngredientsHis_MAT.Value := InputAA(ClientDataSetIngredientsHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2814
      if ClientDataSetInraAfzdHis.IsNull
2815
      then
2816
        ClientDataSetIngredientsdHis.Value := dHis * 100
2817
      else
2818
        ClientDataSetIngredientsdHis.Value := ClientDataSetInraAfzdHis.Value * 100;
2819
      ClientDataSetIngredientsHisd.Value := ClientDataSetIngredientsdHis.Value / 100 * ClientDataSetIngredientsHis.Value;
2820
    end;
2821
    // Arg
2822
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Arg'])
2823
    and ClientDataSetInraAfzArg.IsNull
2824
    then
2825
    begin
2826
      ClientDataSetIngredientsArg.Clear;
2827
      ClientDataSetIngredientsArg_MAT.Clear;
2828
      ClientDataSetIngredientsdArg.Clear;
2829
      ClientDataSetIngredientsArgd.Clear;
2830
    end
2831
    else
2832
    begin
2833
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Arg'])
2834
      then
2835
        ClientDataSetIngredientsArg.Value := OutputAA(ClientDataSetInraAfzArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2836
      else
2837
        ClientDataSetIngredientsArg.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Arg']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2838
      ClientDataSetIngredientsArg_MAT.Value := InputAA(ClientDataSetIngredientsArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2839
      if ClientDataSetInraAfzdArg.IsNull
2840
      then
2841
        ClientDataSetIngredientsdArg.Value := dArg * 100
2842
      else
2843
        ClientDataSetIngredientsdArg.Value := ClientDataSetInraAfzdArg.Value * 100;
2844
      ClientDataSetIngredientsArgd.Value := ClientDataSetIngredientsdArg.Value / 100 * ClientDataSetIngredientsArg.Value;
2845
    end;
2846
    // Ala
2847
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ala'])
2848
    and ClientDataSetInraAfzAla.IsNull
2849
    then
2850
    begin
2851
      ClientDataSetIngredientsAla.Clear;
2852
      ClientDataSetIngredientsAla_MAT.Clear;
2853
      ClientDataSetIngredientsdAla.Clear;
2854
      ClientDataSetIngredientsAlad.Clear;
2855
    end
2856
    else
2857
    begin
2858
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ala'])
2859
      then
2860
        ClientDataSetIngredientsAla.Value := OutputAA(ClientDataSetInraAfzAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2861
      else
2862
        ClientDataSetIngredientsAla.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ala']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2863
      ClientDataSetIngredientsAla_MAT.Value := InputAA(ClientDataSetIngredientsAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2864
      if ClientDataSetInraAfzdAla.IsNull
2865
      then
2866
        ClientDataSetIngredientsdAla.Value := dAla * 100
2867
      else
2868
        ClientDataSetIngredientsdAla.Value := ClientDataSetInraAfzdAla.Value * 100;
2869
      ClientDataSetIngredientsAlad.Value := ClientDataSetIngredientsdAla.Value / 100 * ClientDataSetIngredientsAla.Value;
2870
    end;
2871
    // Asp
2872
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Asp'])
2873
    and ClientDataSetInraAfzAsp.IsNull
2874
    then
2875
    begin
2876
      ClientDataSetIngredientsAsp.Clear;
2877
      ClientDataSetIngredientsAsp_MAT.Clear;
2878
      ClientDataSetIngredientsdAsp.Clear;
2879
      ClientDataSetIngredientsAspd.Clear;
2880
    end
2881
    else
2882
    begin
2883
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Asp'])
2884
      then
2885
        ClientDataSetIngredientsAsp.Value := OutputAA(ClientDataSetInraAfzAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2886
      else
2887
        ClientDataSetIngredientsAsp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Asp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2888
      ClientDataSetIngredientsAsp_MAT.Value := InputAA(ClientDataSetIngredientsAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2889
      if ClientDataSetInraAfzdAsp.IsNull
2890
      then
2891
        ClientDataSetIngredientsdAsp.Value := dAsp * 100
2892
      else
2893
        ClientDataSetIngredientsdAsp.Value := ClientDataSetInraAfzdAsp.Value * 100;
2894
      ClientDataSetIngredientsAspd.Value := ClientDataSetIngredientsdAsp.Value / 100 * ClientDataSetIngredientsAsp.Value;
2895
    end;
2896
    // Glu
2897
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Glu'])
2898
    and ClientDataSetInraAfzGlu.IsNull
2899
    then
2900
    begin
2901
      ClientDataSetIngredientsGlu.Clear;
2902
      ClientDataSetIngredientsGlu_MAT.Clear;
2903
      ClientDataSetIngredientsdGlu.Clear;
2904
      ClientDataSetIngredientsGlud.Clear;
2905
    end
2906
    else
2907
    begin
2908
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Glu'])
2909
      then
2910
        ClientDataSetIngredientsGlu.Value := OutputAA(ClientDataSetInraAfzGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2911
      else
2912
        ClientDataSetIngredientsGlu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Glu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2913
      ClientDataSetIngredientsGlu_MAT.Value := InputAA(ClientDataSetIngredientsGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2914
      if ClientDataSetInraAfzdGlu.IsNull
2915
      then
2916
        ClientDataSetIngredientsdGlu.Value := dGlu * 100
2917
      else
2918
        ClientDataSetIngredientsdGlu.Value := ClientDataSetInraAfzdGlu.Value * 100;
2919
      ClientDataSetIngredientsGlud.Value := ClientDataSetIngredientsdGlu.Value / 100 * ClientDataSetIngredientsGlu.Value;
2920
    end;
2921
    // Gly
2922
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Gly'])
2923
    and ClientDataSetInraAfzGly.IsNull
2924
    then
2925
    begin
2926
      ClientDataSetIngredientsGly.Clear;
2927
      ClientDataSetIngredientsGly_MAT.Clear;
2928
      ClientDataSetIngredientsdGly.Clear;
2929
      ClientDataSetIngredientsGlyd.Clear;
2930
    end
2931
    else
2932
    begin
2933
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Gly'])
2934
      then
2935
        ClientDataSetIngredientsGly.Value := OutputAA(ClientDataSetInraAfzGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2936
      else
2937
        ClientDataSetIngredientsGly.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Gly']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2938
      ClientDataSetIngredientsGly_MAT.Value := InputAA(ClientDataSetIngredientsGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2939
      if ClientDataSetInraAfzdGly.IsNull
2940
      then
2941
        ClientDataSetIngredientsdGly.Value := dGly * 100
2942
      else
2943
        ClientDataSetIngredientsdGly.Value := ClientDataSetInraAfzdGly.Value * 100;
2944
      ClientDataSetIngredientsGlyd.Value := ClientDataSetIngredientsdGly.Value / 100 * ClientDataSetIngredientsGly.Value;
2945
    end;
2946
    // Ser
2947
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ser'])
2948
    and ClientDataSetInraAfzSer.IsNull
2949
    then
2950
    begin
2951
      ClientDataSetIngredientsSer.Clear;
2952
      ClientDataSetIngredientsSer_MAT.Clear;
2953
      ClientDataSetIngredientsdSer.Clear;
2954
      ClientDataSetIngredientsSerd.Clear;
2955
    end
2956
    else
2957
    begin
2958
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ser'])
2959
      then
2960
        ClientDataSetIngredientsSer.Value := OutputAA(ClientDataSetInraAfzSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2961
      else
2962
        ClientDataSetIngredientsSer.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ser']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2963
      ClientDataSetIngredientsSer_MAT.Value := InputAA(ClientDataSetIngredientsSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2964
      if ClientDataSetInraAfzdSer.IsNull
2965
      then
2966
        ClientDataSetIngredientsdSer.Value := dSer * 100
2967
      else
2968
        ClientDataSetIngredientsdSer.Value := ClientDataSetInraAfzdSer.Value * 100;
2969
      ClientDataSetIngredientsSerd.Value := ClientDataSetIngredientsdSer.Value / 100 * ClientDataSetIngredientsSer.Value;
2970
    end;
2971
    // Pro
2972
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Pro'])
2973
    and ClientDataSetInraAfzPro.IsNull
2974
    then
2975
    begin
2976
      ClientDataSetIngredientsPro.Clear;
2977
      ClientDataSetIngredientsPro_MAT.Clear;
2978
      ClientDataSetIngredientsdPro.Clear;
2979
      ClientDataSetIngredientsProd.Clear;
2980
    end
2981
    else
2982
    begin
2983
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Pro'])
2984
      then
2985
        ClientDataSetIngredientsPro.Value := OutputAA(ClientDataSetInraAfzPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2986
      else
2987
        ClientDataSetIngredientsPro.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Pro']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2988
      ClientDataSetIngredientsPro_MAT.Value := InputAA(ClientDataSetIngredientsPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2989
      if ClientDataSetInraAfzdPro.IsNull
2990
      then
2991
        ClientDataSetIngredientsdPro.Value := dPro * 100
2992
      else
2993
        ClientDataSetIngredientsdPro.Value := ClientDataSetInraAfzdPro.Value * 100;
2994
      ClientDataSetIngredientsProd.Value := ClientDataSetIngredientsdPro.Value / 100 * ClientDataSetIngredientsPro.Value;
2995
    end;
2996
  end;
2997
  // Min?raux
2998
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
2999
  then
3000
    if ClientDataSetInraAfzCa.IsNull
3001
    then
3002
      ClientDataSetIngredientsCa.Clear
3003
    else
3004
      ClientDataSetIngredientsCa.Value := OutputMinerals(ClientDataSetInraAfzCa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3005
  else
3006
    ClientDataSetIngredientsCa.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ca']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3007
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
3008
  then
3009
    if ClientDataSetInraAfzP.IsNull
3010
    then
3011
      ClientDataSetIngredientsP.Clear
3012
    else
3013
      ClientDataSetIngredientsP.Value := OutputMinerals(ClientDataSetInraAfzP.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3014
  else
3015
    ClientDataSetIngredientsP.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['P']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3016
  if ClientDataSetIngredientsP.Value = 0
3017
  then // En l'absence de P, il n'y a pas de dP
3018
  begin
3019
    ClientDataSetIngredientsdP.Clear;
3020
    ClientDataSetIngredientsdPphy.Clear;
3021
  end
3022
  else
3023
  begin
3024
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
3025
    then
3026
      if ClientDataSetInraAfzdP.IsNull
3027
      then // Par d?faut dP = 20%
3028
        ClientDataSetIngredientsdP.Value := 20
3029
      else
3030
        ClientDataSetIngredientsdP.Value := ClientDataSetInraAfzdP.Value * 100
3031
    else
3032
      ClientDataSetIngredientsdP.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dP']) * 100;
3033
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
3034
    then
3035
      if ClientDataSetInraAfzdPphy.IsNull
3036
      then // Par d?faut dPphy = dP
3037
        ClientDataSetIngredientsdPphy.Value := ClientDataSetIngredientsdP.Value
3038
      else
3039
        ClientDataSetIngredientsdPphy.Value := ClientDataSetInraAfzdPphy.Value * 100
3040
    else
3041
      ClientDataSetIngredientsdPphy.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPphy']) * 100;
3042
  end;
3043
  // Autres rapports
3044
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
3045
  then
3046
    ClientDataSetIngredientsLysd_ENc.Clear
3047
  else
3048
    if FormOptions.Energy = 0
3049
    then // g / MJ
3050
      if FormOptions.AA = 0
3051
      then // % (conversion)
3052
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value
3053
      else // g/kg
3054
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value
3055
    else // g / 1000 kcal
3056
      if FormOptions.AA = 0
3057
      then // % (conversion)
3058
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value * 1000
3059
      else // g/kg
3060
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value * 1000;
3061
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENt.IsNull or (ClientDataSetIngredientsENt.Value = 0)
3062
  then
3063
    ClientDataSetIngredientsLysd_ENt.Clear
3064
  else
3065
    if FormOptions.Energy = 0
3066
    then // g / MJ
3067
      if FormOptions.AA = 0
3068
      then // % (conversion)
3069
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value
3070
      else // g/kg
3071
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value
3072
    else // g / 1000 kcal
3073
      if FormOptions.AA = 0
3074
      then // % (conversion)
3075
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value * 1000
3076
      else // g/kg
3077
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value * 1000;
3078
end;
3079
3080
procedure TDataModuleDeclaration.CalcFeed;
3081
// Renseigner l'enregistrement courant de ClientDataSetFeeds
3082
// ? partir de l'enregistrement courant de TableFeeds
3083
// en tenant compte des unit?s configur?es
3084
const
3085
  a = 1.026;
3086
  b = 0.00263;
3087
var
3088
  Ratio, CoefPhytase, PdEndo, PhytaseEndo, PhytaseMicro, PdMicro: Double;
3089
begin
3090
  if ClientDataSetComposition.RecordCount = 0
3091
  then // En l'absence de composition cent?simale toutes les valeurs sont nulles
3092
  begin
3093
    // Analyse proximale
3094
    ClientDataSetFeedsMS.Clear;
3095
    ClientDataSetFeedsMS2.Clear;
3096
    ClientDataSetFeedsMM.Clear;
3097
    ClientDataSetFeedsMAT.Clear;
3098
    ClientDataSetFeedsMG.Clear;
3099
    ClientDataSetFeedsCB.Clear;
3100
    ClientDataSetFeedsNDF.Clear;
3101
    ClientDataSetFeedsADF.Clear;
3102
    ClientDataSetFeedsADL.Clear;
3103
    ClientDataSetFeedsAmidon.Clear;
3104
    ClientDataSetFeedsSucres.Clear;
3105
    // Energie
3106
    ClientDataSetFeedsEB.Clear;
3107
    ClientDataSetFeedsEDc.Clear;
3108
    ClientDataSetFeedsEMc.Clear;
3109
    ClientDataSetFeedsENc.Clear;
3110
    ClientDataSetFeedsEDt.Clear;
3111
    ClientDataSetFeedsEMt.Clear;
3112
    ClientDataSetFeedsENt.Clear;
3113
    // Digestibilit? f?cale de l'azote
3114
    ClientDataSetFeedsdNc.Clear;
3115
    ClientDataSetFeedsdNt.Clear;
3116
    // Acides amin?s
3117
    ClientDataSetFeedsLys.Clear;
3118
    ClientDataSetFeedsThr.Clear;
3119
    ClientDataSetFeedsMet.Clear;
3120
    ClientDataSetFeedsCys.Clear;
3121
    ClientDataSetFeedsMetCys.Clear;
3122
    ClientDataSetFeedsTrp.Clear;
3123
    ClientDataSetFeedsIle.Clear;
3124
    ClientDataSetFeedsVal.Clear;
3125
    ClientDataSetFeedsLeu.Clear;
3126
    ClientDataSetFeedsPhe.Clear;
3127
    ClientDataSetFeedsTyr.Clear;
3128
    ClientDataSetFeedsPheTyr.Clear;
3129
    ClientDataSetFeedsHis.Clear;
3130
    ClientDataSetFeedsArg.Clear;
3131
    ClientDataSetFeedsAla.Clear;
3132
    ClientDataSetFeedsAsp.Clear;
3133
    ClientDataSetFeedsGlu.Clear;
3134
    ClientDataSetFeedsGly.Clear;
3135
    ClientDataSetFeedsSer.Clear;
3136
    ClientDataSetFeedsPro.Clear;
3137
    ClientDataSetFeedsLysd.Clear;
3138
    ClientDataSetFeedsThrd.Clear;
3139
    ClientDataSetFeedsMetd.Clear;
3140
    ClientDataSetFeedsCysd.Clear;
3141
    ClientDataSetFeedsMetCysd.Clear;
3142
    ClientDataSetFeedsTrpd.Clear;
3143
    ClientDataSetFeedsIled.Clear;
3144
    ClientDataSetFeedsVald.Clear;
3145
    ClientDataSetFeedsLeud.Clear;
3146
    ClientDataSetFeedsPhed.Clear;
3147
    ClientDataSetFeedsTyrd.Clear;
3148
    ClientDataSetFeedsPheTyrd.Clear;
3149
    ClientDataSetFeedsHisd.Clear;
3150
    ClientDataSetFeedsArgd.Clear;
3151
    ClientDataSetFeedsAlad.Clear;
3152
    ClientDataSetFeedsAspd.Clear;
3153
    ClientDataSetFeedsGlud.Clear;
3154
    ClientDataSetFeedsGlyd.Clear;
3155
    ClientDataSetFeedsSerd.Clear;
3156
    ClientDataSetFeedsProd.Clear;
3157
    // Min?raux
3158
    ClientDataSetFeedsCa.Clear;
3159
    ClientDataSetFeedsP.Clear;
3160
    ClientDataSetFeedsPd.Clear;
3161
  end
3162
  else
3163
  begin
3164
    // COMPOSITON CHIMIQUE - Initialisation ? z?ro
3165
    // Analyse proximale
3166
    ClientDataSetFeedsMS.Value := 0;
3167
    ClientDataSetFeedsMM.Value := 0;
3168
    ClientDataSetFeedsMAT.Value := 0;
3169
    ClientDataSetFeedsMG.Value := 0;
3170
    ClientDataSetFeedsCB.Value := 0;
3171
    ClientDataSetFeedsNDF.Value := 0;
3172
    ClientDataSetFeedsADF.Value := 0;
3173
    ClientDataSetFeedsADL.Value := 0;
3174
    ClientDataSetFeedsAmidon.Value := 0;
3175
    ClientDataSetFeedsSucres.Value := 0;
3176
    // Energie
3177
    ClientDataSetFeedsEB.Value := 0;
3178
    ClientDataSetFeedsEDc.Value := 0;
3179
    ClientDataSetFeedsEMc.Value := 0;
3180
    ClientDataSetFeedsENc.Value := 0;
3181
    ClientDataSetFeedsEDt.Value := 0;
3182
    ClientDataSetFeedsEMt.Value := 0;
3183
    ClientDataSetFeedsENt.Value := 0;
3184
    // Digestibilit? f?cale de l'azote
3185
    ClientDataSetFeedsdNc.Value := 0;
3186
    ClientDataSetFeedsdNt.Value := 0;
3187
    // Acides amin?s
3188
    ClientDataSetFeedsLys.Value := 0;
3189
    ClientDataSetFeedsThr.Value := 0;
3190
    ClientDataSetFeedsMet.Value := 0;
3191
    ClientDataSetFeedsCys.Value := 0;
3192
    ClientDataSetFeedsMetCys.Value := 0;
3193
    ClientDataSetFeedsTrp.Value := 0;
3194
    ClientDataSetFeedsIle.Value := 0;
3195
    ClientDataSetFeedsVal.Value := 0;
3196
    ClientDataSetFeedsLeu.Value := 0;
3197
    ClientDataSetFeedsPhe.Value := 0;
3198
    ClientDataSetFeedsTyr.Value := 0;
3199
    ClientDataSetFeedsPheTyr.Value := 0;
3200
    ClientDataSetFeedsHis.Value := 0;
3201
    ClientDataSetFeedsArg.Value := 0;
3202
    ClientDataSetFeedsAla.Value := 0;
3203
    ClientDataSetFeedsAsp.Value := 0;
3204
    ClientDataSetFeedsGlu.Value := 0;
3205
    ClientDataSetFeedsGly.Value := 0;
3206
    ClientDataSetFeedsSer.Value := 0;
3207
    ClientDataSetFeedsPro.Value := 0;
3208
    ClientDataSetFeedsLysd.Value := 0;
3209
    ClientDataSetFeedsThrd.Value := 0;
3210
    ClientDataSetFeedsMetd.Value := 0;
3211
    ClientDataSetFeedsCysd.Value := 0;
3212
    ClientDataSetFeedsMetCysd.Value := 0;
3213
    ClientDataSetFeedsTrpd.Value := 0;
3214
    ClientDataSetFeedsIled.Value := 0;
3215
    ClientDataSetFeedsVald.Value := 0;
3216
    ClientDataSetFeedsLeud.Value := 0;
3217
    ClientDataSetFeedsPhed.Value := 0;
3218
    ClientDataSetFeedsTyrd.Value := 0;
3219
    ClientDataSetFeedsPheTyrd.Value := 0;
3220
    ClientDataSetFeedsHisd.Value := 0;
3221
    ClientDataSetFeedsArgd.Value := 0;
3222
    ClientDataSetFeedsAlad.Value := 0;
3223
    ClientDataSetFeedsAspd.Value := 0;
3224
    ClientDataSetFeedsGlud.Value := 0;
3225
    ClientDataSetFeedsGlyd.Value := 0;
3226
    ClientDataSetFeedsSerd.Value := 0;
3227
    ClientDataSetFeedsProd.Value := 0;
3228
    // Min?raux
3229
    ClientDataSetFeedsCa.Value := 0;
3230
    ClientDataSetFeedsP.Value := 0;
3231
    ClientDataSetFeedsPd.Value := 0;
3232
    PdEndo := 0;
3233
    ClientDataSetComposition.First;
3234
    while not ClientDataSetComposition.Eof do
3235
    begin
3236
      if ClientDataSetCompositionUser.Value
3237
      then
3238
        ClientDataSetIngredients.Filter := Format('Id = %d and User', [ClientDataSetCompositionIngredient.Value])
3239
      else
3240
        ClientDataSetIngredients.Filter := Format('Id = %d and not User', [ClientDataSetCompositionIngredient.Value]);
3241
      ClientDataSetIngredients.Filtered := True;
3242
      // COMPOSITON CHIMIQUE - Incr?mentation
3243
      Ratio := InputIncorporation(ClientDataSetCompositionLevel.Value, FormOptions.Incorporation);
3244
      ClientDataSetFeedsMS.Value := ClientDataSetFeedsMS.Value + ClientDataSetCompositionMS.Value * Ratio;
3245
      if FormOptions.Expression = 0
3246
      then // Conversion frais -> sec (mati?re s?che de la mati?re premi?re)
3247
        Ratio := Ratio / InputProximal(ClientDataSetIngredientsMS.Value, 1, 1, FormOptions.Proximal);
3248
      RapMS := InputProximal(ClientDataSetCompositionMS.Value, 1, 1, FormOptions.Proximal);
3249
      // Conversion sec -> frais (mati?re s?che de la composition)
3250
      Ratio := Ratio * RapMS;
3251
      // Analyse proximale
3252
      ClientDataSetFeedsMM.Value := ClientDataSetFeedsMM.Value + ClientDataSetIngredientsMM.Value * Ratio;
3253
      ClientDataSetFeedsMAT.Value := ClientDataSetFeedsMAT.Value + ClientDataSetIngredientsMAT.Value * Ratio;
3254
      if not ClientDataSetFeedsMG.IsNull
3255
      then
3256
        if ClientDataSetIngredientsMG.IsNull
3257
        then
3258
          ClientDataSetFeedsMG.Clear
3259
        else
3260
          ClientDataSetFeedsMG.Value := ClientDataSetFeedsMG.Value + ClientDataSetIngredientsMG.Value * Ratio;
3261
      if not ClientDataSetFeedsCB.IsNull
3262
      then
3263
        if ClientDataSetIngredientsCB.IsNull
3264
        then
3265
          ClientDataSetFeedsCB.Clear
3266
        else
3267
          ClientDataSetFeedsCB.Value := ClientDataSetFeedsCB.Value + ClientDataSetIngredientsCB.Value * Ratio;
3268
      if not ClientDataSetFeedsNDF.IsNull
3269
      then
3270
        if ClientDataSetIngredientsNDF.IsNull
3271
        then
3272
          ClientDataSetFeedsNDF.Clear
3273
        else
3274
          ClientDataSetFeedsNDF.Value := ClientDataSetFeedsNDF.Value + ClientDataSetIngredientsNDF.Value * Ratio;
3275
      if not ClientDataSetFeedsADF.IsNull
3276
      then
3277
        if ClientDataSetIngredientsADF.IsNull
3278
        then
3279
          ClientDataSetFeedsADF.Clear
3280
        else
3281
          ClientDataSetFeedsADF.Value := ClientDataSetFeedsADF.Value + ClientDataSetIngredientsADF.Value * Ratio;
3282
      if not ClientDataSetFeedsADL.IsNull
3283
      then
3284
        if ClientDataSetIngredientsADL.IsNull
3285
        then
3286
          ClientDataSetFeedsADL.Clear
3287
        else
3288
          ClientDataSetFeedsADL.Value := ClientDataSetFeedsADL.Value + ClientDataSetIngredientsADL.Value * Ratio;
3289
      if not ClientDataSetFeedsAmidon.IsNull
3290
      then
3291
        if ClientDataSetIngredientsAmidon.IsNull
3292
        then
3293
          ClientDataSetFeedsAmidon.Clear
3294
        else
3295
          ClientDataSetFeedsAmidon.Value := ClientDataSetFeedsAmidon.Value + ClientDataSetIngredientsAmidon.Value * Ratio;
3296
      if not ClientDataSetFeedsSucres.IsNull
3297
      then
3298
        if ClientDataSetIngredientsSucres.IsNull
3299
        then
3300
          ClientDataSetFeedsSucres.Clear
3301
        else
3302
          ClientDataSetFeedsSucres.Value := ClientDataSetFeedsSucres.Value + ClientDataSetIngredientsSucres.Value * Ratio;
3303
      // Energie
3304
      if not ClientDataSetFeedsEB.IsNull
3305
      then
3306
        if ClientDataSetIngredientsEB.IsNull
3307
        then
3308
          ClientDataSetFeedsEB.Clear
3309
        else
3310
          ClientDataSetFeedsEB.Value := ClientDataSetFeedsEB.Value + ClientDataSetIngredientsEB.Value * Ratio;
3311
      if not ClientDataSetFeedsEDc.IsNull
3312
      then
3313
        if ClientDataSetIngredientsEDc.IsNull
3314
        then
3315
          ClientDataSetFeedsEDc.Clear
3316
        else
3317
          ClientDataSetFeedsEDc.Value := ClientDataSetFeedsEDc.Value + ClientDataSetIngredientsEDc.Value * Ratio;
3318
      if not ClientDataSetFeedsEMc.IsNull
3319
      then
3320
        if ClientDataSetIngredientsEMc.IsNull
3321
        then
3322
          ClientDataSetFeedsEMc.Clear
3323
        else
3324
          ClientDataSetFeedsEMc.Value := ClientDataSetFeedsEMc.Value + ClientDataSetIngredientsEMc.Value * Ratio;
3325
      if not ClientDataSetFeedsENc.IsNull
3326
      then
3327
        if ClientDataSetIngredientsENc.IsNull
3328
        then
3329
          ClientDataSetFeedsENc.Clear
3330
        else
3331
          ClientDataSetFeedsENc.Value := ClientDataSetFeedsENc.Value + ClientDataSetIngredientsENc.Value * Ratio;
3332
      if not ClientDataSetFeedsEDt.IsNull
3333
      then
3334
        if ClientDataSetIngredientsEDt.IsNull
3335
        then
3336
          ClientDataSetFeedsEDt.Clear
3337
        else
3338
          ClientDataSetFeedsEDt.Value := ClientDataSetFeedsEDt.Value + ClientDataSetIngredientsEDt.Value * Ratio;
3339
      if not ClientDataSetFeedsEMt.IsNull
3340
      then
3341
        if ClientDataSetIngredientsEMt.IsNull
3342
        then
3343
          ClientDataSetFeedsEMt.Clear
3344
        else
3345
          ClientDataSetFeedsEMt.Value := ClientDataSetFeedsEMt.Value + ClientDataSetIngredientsEMt.Value * Ratio;
3346
      if not ClientDataSetFeedsENt.IsNull
3347
      then
3348
        if ClientDataSetIngredientsENt.IsNull
3349
        then
3350
          ClientDataSetFeedsENt.Clear
3351
        else
3352
          ClientDataSetFeedsENt.Value := ClientDataSetFeedsENt.Value + ClientDataSetIngredientsENt.Value * Ratio;
3353
      // Digestibilit? f?cale de l'azote
3354
      if not ClientDataSetFeedsdNc.IsNull
3355
      then
3356
        if ClientDataSetIngredientsdNc.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3357
        then // Ne devrait pas se produire
3358
          ClientDataSetFeedsdNc.Clear
3359
        else // MATd = MAT * dN
3360
          ClientDataSetFeedsdNc.Value := ClientDataSetFeedsdNc.Value + ClientDataSetIngredientsMAT.Value * ClientDataSetIngredientsdNc.Value / 100 * Ratio;
3361
      if not ClientDataSetFeedsdNt.IsNull
3362
      then
3363
        if ClientDataSetIngredientsdNt.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3364
        then // Ne devrait pas se produire
3365
          ClientDataSetFeedsdNt.Clear
3366
        else // MATd = MAT * dN
3367
          ClientDataSetFeedsdNt.Value := ClientDataSetFeedsdNt.Value + ClientDataSetIngredientsMAT.Value * ClientDataSetIngredientsdNt.Value / 100 * Ratio;
3368
      // Acides amin?s
3369
      if not ClientDataSetFeedsLys.IsNull
3370
      then
3371
        if ClientDataSetIngredientsLys.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3372
        then
3373
        begin
3374
          ClientDataSetFeedsLys.Clear;
3375
          ClientDataSetFeedsLysd.Clear;
3376
        end
3377
        else
3378
        begin
3379
          ClientDataSetFeedsLys.Value := ClientDataSetFeedsLys.Value + ClientDataSetIngredientsLys.Value * Ratio;
3380
          ClientDataSetFeedsLysd.Value := ClientDataSetFeedsLysd.Value + ClientDataSetIngredientsLysd.Value * Ratio;
3381
        end;
3382
      if not ClientDataSetFeedsThr.IsNull
3383
      then
3384
        if ClientDataSetIngredientsThr.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3385
        then
3386
        begin
3387
          ClientDataSetFeedsThr.Clear;
3388
          ClientDataSetFeedsThrd.Clear;
3389
        end
3390
        else
3391
        begin
3392
          ClientDataSetFeedsThr.Value := ClientDataSetFeedsThr.Value + ClientDataSetIngredientsThr.Value * Ratio;
3393
          ClientDataSetFeedsThrd.Value := ClientDataSetFeedsThrd.Value + ClientDataSetIngredientsThrd.Value * Ratio;
3394
        end;
3395
      if not ClientDataSetFeedsMet.IsNull
3396
      then
3397
        if ClientDataSetIngredientsMet.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3398
        then
3399
        begin
3400
          ClientDataSetFeedsMet.Clear;
3401
          ClientDataSetFeedsMetd.Clear;
3402
        end
3403
        else
3404
        begin
3405
          ClientDataSetFeedsMet.Value := ClientDataSetFeedsMet.Value + ClientDataSetIngredientsMet.Value * Ratio;
3406
          ClientDataSetFeedsMetd.Value := ClientDataSetFeedsMetd.Value + ClientDataSetIngredientsMetd.Value * Ratio;
3407
        end;
3408
      if not ClientDataSetFeedsCys.IsNull
3409
      then
3410
        if ClientDataSetIngredientsCys.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3411
        then
3412
        begin
3413
          ClientDataSetFeedsCys.Clear;
3414
          ClientDataSetFeedsCysd.Clear;
3415
        end
3416
        else
3417
        begin
3418
          ClientDataSetFeedsCys.Value := ClientDataSetFeedsCys.Value + ClientDataSetIngredientsCys.Value * Ratio;
3419
          ClientDataSetFeedsCysd.Value := ClientDataSetFeedsCysd.Value + ClientDataSetIngredientsCysd.Value * Ratio;
3420
        end;
3421
      if not ClientDataSetFeedsMetCys.IsNull
3422
      then
3423
        if ClientDataSetIngredientsMetCys.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3424
        then
3425
        begin
3426
          ClientDataSetFeedsMetCys.Clear;
3427
          ClientDataSetFeedsMetCysd.Clear;
3428
        end
3429
        else
3430
        begin
3431
          ClientDataSetFeedsMetCys.Value := ClientDataSetFeedsMetCys.Value + ClientDataSetIngredientsMetCys.Value * Ratio;
3432
          ClientDataSetFeedsMetCysd.Value := ClientDataSetFeedsMetCysd.Value + ClientDataSetIngredientsMetCysd.Value * Ratio;
3433
        end;
3434
      if not ClientDataSetFeedsTrp.IsNull
3435
      then
3436
        if ClientDataSetIngredientsTrp.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3437
        then
3438
        begin
3439
          ClientDataSetFeedsTrp.Clear;
3440
          ClientDataSetFeedsTrpd.Clear;
3441
        end
3442
        else
3443
        begin
3444
          ClientDataSetFeedsTrp.Value := ClientDataSetFeedsTrp.Value + ClientDataSetIngredientsTrp.Value * Ratio;
3445
          ClientDataSetFeedsTrpd.Value := ClientDataSetFeedsTrpd.Value + ClientDataSetIngredientsTrpd.Value * Ratio;
3446
        end;
3447
      if not ClientDataSetFeedsIle.IsNull
3448
      then
3449
        if ClientDataSetIngredientsIle.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3450
        then
3451
        begin
3452
          ClientDataSetFeedsIle.Clear;
3453
          ClientDataSetFeedsIled.Clear;
3454
        end
3455
        else
3456
        begin
3457
          ClientDataSetFeedsIle.Value := ClientDataSetFeedsIle.Value + ClientDataSetIngredientsIle.Value * Ratio;
3458
          ClientDataSetFeedsIled.Value := ClientDataSetFeedsIled.Value + ClientDataSetIngredientsIled.Value * Ratio;
3459
        end;
3460
      if not ClientDataSetFeedsVal.IsNull
3461
      then
3462
        if ClientDataSetIngredientsVal.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3463
        then
3464
        begin
3465
          ClientDataSetFeedsVal.Clear;
3466
          ClientDataSetFeedsVald.Clear;
3467
        end
3468
        else
3469
        begin
3470
          ClientDataSetFeedsVal.Value := ClientDataSetFeedsVal.Value + ClientDataSetIngredientsVal.Value * Ratio;
3471
          ClientDataSetFeedsVald.Value := ClientDataSetFeedsVald.Value + ClientDataSetIngredientsVald.Value * Ratio;
3472
        end;
3473
      if not ClientDataSetFeedsLeu.IsNull
3474
      then
3475
        if ClientDataSetIngredientsLeu.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3476
        then
3477
        begin
3478
          ClientDataSetFeedsLeu.Clear;
3479
          ClientDataSetFeedsLeud.Clear;
3480
        end
3481
        else
3482
        begin
3483
          ClientDataSetFeedsLeu.Value := ClientDataSetFeedsLeu.Value + ClientDataSetIngredientsLeu.Value * Ratio;
3484
          ClientDataSetFeedsLeud.Value := ClientDataSetFeedsLeud.Value + ClientDataSetIngredientsLeud.Value * Ratio;
3485
        end;
3486
      if not ClientDataSetFeedsPhe.IsNull
3487
      then
3488
        if ClientDataSetIngredientsPhe.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3489
        then
3490
        begin
3491
          ClientDataSetFeedsPhe.Clear;
3492
          ClientDataSetFeedsPhed.Clear;
3493
        end
3494
        else
3495
        begin
3496
          ClientDataSetFeedsPhe.Value := ClientDataSetFeedsPhe.Value + ClientDataSetIngredientsPhe.Value * Ratio;
3497
          ClientDataSetFeedsPhed.Value := ClientDataSetFeedsPhed.Value + ClientDataSetIngredientsPhed.Value * Ratio;
3498
        end;
3499
      if not ClientDataSetFeedsTyr.IsNull
3500
      then
3501
        if ClientDataSetIngredientsTyr.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3502
        then
3503
        begin
3504
          ClientDataSetFeedsTyr.Clear;
3505
          ClientDataSetFeedsTyrd.Clear;
3506
        end
3507
        else
3508
        begin
3509
          ClientDataSetFeedsTyr.Value := ClientDataSetFeedsTyr.Value + ClientDataSetIngredientsTyr.Value * Ratio;
3510
          ClientDataSetFeedsTyrd.Value := ClientDataSetFeedsTyrd.Value + ClientDataSetIngredientsTyrd.Value * Ratio;
3511
        end;
3512
      if not ClientDataSetFeedsPheTyr.IsNull
3513
      then
3514
        if ClientDataSetIngredientsPheTyr.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3515
        then
3516
        begin
3517
          ClientDataSetFeedsPheTyr.Clear;
3518
          ClientDataSetFeedsPheTyrd.Clear;
3519
        end
3520
        else
3521
        begin
3522
          ClientDataSetFeedsPheTyr.Value := ClientDataSetFeedsPheTyr.Value + ClientDataSetIngredientsPheTyr.Value * Ratio;
3523
          ClientDataSetFeedsPheTyrd.Value := ClientDataSetFeedsPheTyrd.Value + ClientDataSetIngredientsPheTyrd.Value * Ratio;
3524
        end;
3525
      if not ClientDataSetFeedsHis.IsNull
3526
      then
3527
        if ClientDataSetIngredientsHis.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3528
        then
3529
        begin
3530
          ClientDataSetFeedsHis.Clear;
3531
          ClientDataSetFeedsHisd.Clear;
3532
        end
3533
        else
3534
        begin
3535
          ClientDataSetFeedsHis.Value := ClientDataSetFeedsHis.Value + ClientDataSetIngredientsHis.Value * Ratio;
3536
          ClientDataSetFeedsHisd.Value := ClientDataSetFeedsHisd.Value + ClientDataSetIngredientsHisd.Value * Ratio;
3537
        end;
3538
      if not ClientDataSetFeedsArg.IsNull
3539
      then
3540
        if ClientDataSetIngredientsArg.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3541
        then
3542
        begin
3543
          ClientDataSetFeedsArg.Clear;
3544
          ClientDataSetFeedsArgd.Clear;
3545
        end
3546
        else
3547
        begin
3548
          ClientDataSetFeedsArg.Value := ClientDataSetFeedsArg.Value + ClientDataSetIngredientsArg.Value * Ratio;
3549
          ClientDataSetFeedsArgd.Value := ClientDataSetFeedsArgd.Value + ClientDataSetIngredientsArgd.Value * Ratio;
3550
        end;
3551
      if not ClientDataSetFeedsAla.IsNull
3552
      then
3553
        if ClientDataSetIngredientsAla.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3554
        then
3555
        begin
3556
          ClientDataSetFeedsAla.Clear;
3557
          ClientDataSetFeedsAlad.Clear;
3558
        end
3559
        else
3560
        begin
3561
          ClientDataSetFeedsAla.Value := ClientDataSetFeedsAla.Value + ClientDataSetIngredientsAla.Value * Ratio;
3562
          ClientDataSetFeedsAlad.Value := ClientDataSetFeedsAlad.Value + ClientDataSetIngredientsAlad.Value * Ratio;
3563
        end;
3564
      if not ClientDataSetFeedsAsp.IsNull
3565
      then
3566
        if ClientDataSetIngredientsAsp.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3567
        then
3568
        begin
3569
          ClientDataSetFeedsAsp.Clear;
3570
          ClientDataSetFeedsAspd.Clear;
3571
        end
3572
        else
3573
        begin
3574
          ClientDataSetFeedsAsp.Value := ClientDataSetFeedsAsp.Value + ClientDataSetIngredientsAsp.Value * Ratio;
3575
          ClientDataSetFeedsAspd.Value := ClientDataSetFeedsAspd.Value + ClientDataSetIngredientsAspd.Value * Ratio;
3576
        end;
3577
      if not ClientDataSetFeedsGlu.IsNull
3578
      then
3579
        if ClientDataSetIngredientsGlu.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3580
        then
3581
        begin
3582
          ClientDataSetFeedsGlu.Clear;
3583
          ClientDataSetFeedsGlud.Clear;
3584
        end
3585
        else
3586
        begin
3587
          ClientDataSetFeedsGlu.Value := ClientDataSetFeedsGlu.Value + ClientDataSetIngredientsGlu.Value * Ratio;
3588
          ClientDataSetFeedsGlud.Value := ClientDataSetFeedsGlud.Value + ClientDataSetIngredientsGlud.Value * Ratio;
3589
        end;
3590
      if not ClientDataSetFeedsGly.IsNull
3591
      then
3592
        if ClientDataSetIngredientsGly.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3593
        then
3594
        begin
3595
          ClientDataSetFeedsGly.Clear;
3596
          ClientDataSetFeedsGlyd.Clear;
3597
        end
3598
        else
3599
        begin
3600
          ClientDataSetFeedsGly.Value := ClientDataSetFeedsGly.Value + ClientDataSetIngredientsGly.Value * Ratio;
3601
          ClientDataSetFeedsGlyd.Value := ClientDataSetFeedsGlyd.Value + ClientDataSetIngredientsGlyd.Value * Ratio;
3602
        end;
3603
      if not ClientDataSetFeedsSer.IsNull
3604
      then
3605
        if ClientDataSetIngredientsSer.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3606
        then
3607
        begin
3608
          ClientDataSetFeedsSer.Clear;
3609
          ClientDataSetFeedsSerd.Clear;
3610
        end
3611
        else
3612
        begin
3613
          ClientDataSetFeedsSer.Value := ClientDataSetFeedsSer.Value + ClientDataSetIngredientsSer.Value * Ratio;
3614
          ClientDataSetFeedsSerd.Value := ClientDataSetFeedsSerd.Value + ClientDataSetIngredientsSerd.Value * Ratio;
3615
        end;
3616
      if not ClientDataSetFeedsPro.IsNull
3617
      then
3618
        if ClientDataSetIngredientsPro.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3619
        then
3620
        begin
3621
          ClientDataSetFeedsPro.Clear;
3622
          ClientDataSetFeedsProd.Clear;
3623
        end
3624
        else
3625
        begin
3626
          ClientDataSetFeedsPro.Value := ClientDataSetFeedsPro.Value + ClientDataSetIngredientsPro.Value * Ratio;
3627
          ClientDataSetFeedsProd.Value := ClientDataSetFeedsProd.Value + ClientDataSetIngredientsProd.Value * Ratio;
3628
        end;
3629
      // Min?raux
3630
      if not ClientDataSetFeedsCa.IsNull
3631
      then
3632
        if ClientDataSetIngredientsCa.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
3633
        then
3634
          ClientDataSetFeedsCa.Clear
3635
        else
3636
          ClientDataSetFeedsCa.Value := ClientDataSetFeedsCa.Value + ClientDataSetIngredientsCa.Value * Ratio;
3637
      if not ClientDataSetFeedsP.IsNull
3638
      then
3639
        if ClientDataSetIngredientsP.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
3640
        then
3641
          ClientDataSetFeedsP.Clear
3642
        else
3643
          ClientDataSetFeedsP.Value := ClientDataSetFeedsP.Value + ClientDataSetIngredientsP.Value * Ratio;
3644
      if not ClientDataSetFeedsPd.IsNull
3645
      then
3646
        if ClientDataSetFeedsPresentation.Value = 0
3647
        then // Farine (dPphy)
3648
          if ClientDataSetIngredientsdPphy.IsNull and (ClientDataSetIngredientsP.Value <> 0) and (ClientDataSetIngredientsMM.Value <> 0)
3649
          then
3650
            ClientDataSetFeedsPd.Clear
3651
          else
3652
            ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value + (ClientDataSetIngredientsdPphy.Value / 100 * ClientDataSetIngredientsP.Value) * Ratio
3653
        else // Granul?s (dP)
3654
          if ClientDataSetIngredientsdP.IsNull and (ClientDataSetIngredientsP.Value <> 0) and (ClientDataSetIngredientsMM.Value <> 0)
3655
          then
3656
            ClientDataSetFeedsPd.Clear
3657
          else
3658
            ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value + (ClientDataSetIngredientsdP.Value / 100 * ClientDataSetIngredientsP.Value) * Ratio;
3659
      PdEndo := PdEndo + ((ClientDataSetIngredientsdPphy.Value - ClientDataSetIngredientsdP.Value) / 100 * ClientDataSetIngredientsP.Value) * Ratio;
3660
      ClientDataSetIngredients.Filtered := False;
3661
      ClientDataSetIngredients.Filter := '';
3662
      ClientDataSetComposition.Next;
3663
    end;
3664
    // Phytase
3665
    if not TableFeeds.FieldIsNull(TableFeeds.FieldIndex['Phytase'])
3666
    and not ClientDataSetFeedsPd.IsNull
3667
    then // Phosphore digestible lib?r? par la phytase
3668
    begin
3669
      PhytaseMicro := ClientDataSetFeedsPhytaseIncorporation.Value;
3670
      ClientDataSetPhytase.Locate('Id', ClientDataSetFeedsPhytaseId.Value, []);
3671
      CoefPhytase := ClientDataSetPhytaseCoef.Value;
3672
      if ClientDataSetFeedsPresentation.Value = 0
3673
      then // Farine (dPphy)
3674
      begin
3675
        if FormOptions.Minerals = 0
3676
        then // Conversion % -> g/kg
3677
          PdEndo := PdEndo / 100 * 1000;
3678
        PdEndo := Min(PdEndo, 0.4); // Limiter ? 0.4 g/kg
3679
        PhytaseEndo := -Ln(1 - PdEndo / a) / (b * CoefPhytase);
3680
        PdMicro := a * (1 - Exp(-b * (PhytaseMicro + PhytaseEndo) * CoefPhytase))
3681
          - a * (1 - Exp(-b * PhytaseEndo * CoefPhytase));
3682
      end
3683
      else // Granul?s (dP)
3684
        PdMicro := a * (1 - Exp(-b * PhytaseMicro * CoefPhytase));
3685
      if FormOptions.Minerals = 0
3686
      then // Conversion g/kg -> %
3687
        PdMicro := PdMicro / 1000 * 100;
3688
      ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value + PdMicro;
3689
    end;
3690
    RapMS := InputProximal(ClientDataSetFeedsMS.Value, 1, 1, FormOptions.Proximal);
3691
    ClientDataSetFeedsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
3692
    if FormOptions.Expression = 1
3693
    then // Conversion frais -> sec (mati?re s?che du r?gime)
3694
    begin
3695
      // Analyse proximale
3696
      ClientDataSetFeedsMM.Value := ClientDataSetFeedsMM.Value / RapMS;
3697
      ClientDataSetFeedsMAT.Value := ClientDataSetFeedsMAT.Value / RapMS;
3698
      if not ClientDataSetFeedsMG.IsNull
3699
      then
3700
        ClientDataSetFeedsMG.Value := ClientDataSetFeedsMG.Value / RapMS;
3701
      if not ClientDataSetFeedsCB.IsNull
3702
      then
3703
        ClientDataSetFeedsCB.Value := ClientDataSetFeedsCB.Value / RapMS;
3704
      if not ClientDataSetFeedsNDF.IsNull
3705
      then
3706
        ClientDataSetFeedsNDF.Value := ClientDataSetFeedsNDF.Value / RapMS;
3707
      if not ClientDataSetFeedsADF.IsNull
3708
      then
3709
        ClientDataSetFeedsADF.Value := ClientDataSetFeedsADF.Value / RapMS;
3710
      if not ClientDataSetFeedsADL.IsNull
3711
      then
3712
        ClientDataSetFeedsADL.Value := ClientDataSetFeedsADL.Value / RapMS;
3713
      if not ClientDataSetFeedsAmidon.IsNull
3714
      then
3715
        ClientDataSetFeedsAmidon.Value := ClientDataSetFeedsAmidon.Value / RapMS;
3716
      if not ClientDataSetFeedsSucres.IsNull
3717
      then
3718
        ClientDataSetFeedsSucres.Value := ClientDataSetFeedsSucres.Value / RapMS;
3719
      // Energie
3720
      if not ClientDataSetFeedsEB.IsNull
3721
      then
3722
        ClientDataSetFeedsEB.Value := ClientDataSetFeedsEB.Value / RapMS;
3723
      if not ClientDataSetFeedsEDc.IsNull
3724
      then
3725
        ClientDataSetFeedsEDc.Value := ClientDataSetFeedsEDc.Value / RapMS;
3726
      if not ClientDataSetFeedsEMc.IsNull
3727
      then
3728
        ClientDataSetFeedsEMc.Value := ClientDataSetFeedsEMc.Value / RapMS;
3729
      if not ClientDataSetFeedsENc.IsNull
3730
      then
3731
        ClientDataSetFeedsENc.Value := ClientDataSetFeedsENc.Value / RapMS;
3732
      if not ClientDataSetFeedsEDt.IsNull
3733
      then
3734
        ClientDataSetFeedsEDt.Value := ClientDataSetFeedsEDt.Value / RapMS;
3735
      if not ClientDataSetFeedsEMt.IsNull
3736
      then
3737
        ClientDataSetFeedsEMt.Value := ClientDataSetFeedsEMt.Value / RapMS;
3738
      if not ClientDataSetFeedsENt.IsNull
3739
      then
3740
        ClientDataSetFeedsENt.Value := ClientDataSetFeedsENt.Value / RapMS;
3741
      // Digestibilit? f?cale de l'azote
3742
      if not ClientDataSetFeedsdNc.IsNull
3743
      then
3744
        ClientDataSetFeedsdNc.Value := ClientDataSetFeedsdNc.Value / RapMS;
3745
      if not ClientDataSetFeedsdNt.IsNull
3746
      then
3747
        ClientDataSetFeedsdNt.Value := ClientDataSetFeedsdNt.Value / RapMS;
3748
      // Acides amin?s
3749
      if not ClientDataSetFeedsLys.IsNull
3750
      then
3751
      begin
3752
        ClientDataSetFeedsLys.Value := ClientDataSetFeedsLys.Value / RapMS;
3753
        ClientDataSetFeedsLysd.Value := ClientDataSetFeedsLysd.Value / RapMS;
3754
      end;
3755
      if not ClientDataSetFeedsThr.IsNull
3756
      then
3757
      begin
3758
        ClientDataSetFeedsThr.Value := ClientDataSetFeedsThr.Value / RapMS;
3759
        ClientDataSetFeedsThrd.Value := ClientDataSetFeedsThrd.Value / RapMS;
3760
      end;
3761
      if not ClientDataSetFeedsMet.IsNull
3762
      then
3763
      begin
3764
        ClientDataSetFeedsMet.Value := ClientDataSetFeedsMet.Value / RapMS;
3765
        ClientDataSetFeedsMetd.Value := ClientDataSetFeedsMetd.Value / RapMS;
3766
      end;
3767
      if not ClientDataSetFeedsCys.IsNull
3768
      then
3769
      begin
3770
        ClientDataSetFeedsCys.Value := ClientDataSetFeedsCys.Value / RapMS;
3771
        ClientDataSetFeedsCysd.Value := ClientDataSetFeedsCysd.Value / RapMS;
3772
      end;
3773
      if not ClientDataSetFeedsMetCys.IsNull
3774
      then
3775
      begin
3776
        ClientDataSetFeedsMetCys.Value := ClientDataSetFeedsMetCys.Value / RapMS;
3777
        ClientDataSetFeedsMetCysd.Value := ClientDataSetFeedsMetCysd.Value / RapMS;
3778
      end;
3779
      if not ClientDataSetFeedsTrp.IsNull
3780
      then
3781
      begin
3782
        ClientDataSetFeedsTrp.Value := ClientDataSetFeedsTrp.Value / RapMS;
3783
        ClientDataSetFeedsTrpd.Value := ClientDataSetFeedsTrpd.Value / RapMS;
3784
      end;
3785
      if not ClientDataSetFeedsIle.IsNull
3786
      then
3787
      begin
3788
        ClientDataSetFeedsIle.Value := ClientDataSetFeedsIle.Value / RapMS;
3789
        ClientDataSetFeedsIled.Value := ClientDataSetFeedsIled.Value / RapMS;
3790
      end;
3791
      if not ClientDataSetFeedsVal.IsNull
3792
      then
3793
      begin
3794
        ClientDataSetFeedsVal.Value := ClientDataSetFeedsVal.Value / RapMS;
3795
        ClientDataSetFeedsVald.Value := ClientDataSetFeedsVald.Value / RapMS;
3796
      end;
3797
      if not ClientDataSetFeedsLeu.IsNull
3798
      then
3799
      begin
3800
        ClientDataSetFeedsLeu.Value := ClientDataSetFeedsLeu.Value / RapMS;
3801
        ClientDataSetFeedsLeud.Value := ClientDataSetFeedsLeud.Value / RapMS;
3802
      end;
3803
      if not ClientDataSetFeedsPhe.IsNull
3804
      then
3805
      begin
3806
        ClientDataSetFeedsPhe.Value := ClientDataSetFeedsPhe.Value / RapMS;
3807
        ClientDataSetFeedsPhed.Value := ClientDataSetFeedsPhed.Value / RapMS;
3808
      end;
3809
      if not ClientDataSetFeedsTyr.IsNull
3810
      then
3811
      begin
3812
        ClientDataSetFeedsTyr.Value := ClientDataSetFeedsTyr.Value / RapMS;
3813
        ClientDataSetFeedsTyrd.Value := ClientDataSetFeedsTyrd.Value / RapMS;
3814
      end;
3815
      if not ClientDataSetFeedsPheTyr.IsNull
3816
      then
3817
      begin
3818
        ClientDataSetFeedsPheTyr.Value := ClientDataSetFeedsPheTyr.Value / RapMS;
3819
        ClientDataSetFeedsPheTyrd.Value := ClientDataSetFeedsPheTyrd.Value / RapMS;
3820
      end;
3821
      if not ClientDataSetFeedsHis.IsNull
3822
      then
3823
      begin
3824
        ClientDataSetFeedsHis.Value := ClientDataSetFeedsHis.Value / RapMS;
3825
        ClientDataSetFeedsHisd.Value := ClientDataSetFeedsHisd.Value / RapMS;
3826
      end;
3827
      if not ClientDataSetFeedsArg.IsNull
3828
      then
3829
      begin
3830
        ClientDataSetFeedsArg.Value := ClientDataSetFeedsArg.Value / RapMS;
3831
        ClientDataSetFeedsArgd.Value := ClientDataSetFeedsArgd.Value / RapMS;
3832
      end;
3833
      if not ClientDataSetFeedsAla.IsNull
3834
      then
3835
      begin
3836
        ClientDataSetFeedsAla.Value := ClientDataSetFeedsAla.Value / RapMS;
3837
        ClientDataSetFeedsAlad.Value := ClientDataSetFeedsAlad.Value / RapMS;
3838
      end;
3839
      if not ClientDataSetFeedsAsp.IsNull
3840
      then
3841
      begin
3842
        ClientDataSetFeedsAsp.Value := ClientDataSetFeedsAsp.Value / RapMS;
3843
        ClientDataSetFeedsAspd.Value := ClientDataSetFeedsAspd.Value / RapMS;
3844
      end;
3845
      if not ClientDataSetFeedsGlu.IsNull
3846
      then
3847
      begin
3848
        ClientDataSetFeedsGlu.Value := ClientDataSetFeedsGlu.Value / RapMS;
3849
        ClientDataSetFeedsGlud.Value := ClientDataSetFeedsGlud.Value / RapMS;
3850
      end;
3851
      if not ClientDataSetFeedsGly.IsNull
3852
      then
3853
      begin
3854
        ClientDataSetFeedsGly.Value := ClientDataSetFeedsGly.Value / RapMS;
3855
        ClientDataSetFeedsGlyd.Value := ClientDataSetFeedsGlyd.Value / RapMS;
3856
      end;
3857
      if not ClientDataSetFeedsSer.IsNull
3858
      then
3859
      begin
3860
        ClientDataSetFeedsSer.Value := ClientDataSetFeedsSer.Value / RapMS;
3861
        ClientDataSetFeedsSerd.Value := ClientDataSetFeedsSerd.Value / RapMS;
3862
      end;
3863
      if not ClientDataSetFeedsPro.IsNull
3864
      then
3865
      begin
3866
        ClientDataSetFeedsPro.Value := ClientDataSetFeedsPro.Value / RapMS;
3867
        ClientDataSetFeedsProd.Value := ClientDataSetFeedsProd.Value / RapMS;
3868
      end;
3869
      // Min?raux
3870
      if not ClientDataSetFeedsCa.IsNull
3871
      then
3872
        ClientDataSetFeedsCa.Value := ClientDataSetFeedsCa.Value / RapMS;
3873
      if not ClientDataSetFeedsP.IsNull
3874
      then
3875
        ClientDataSetFeedsP.Value := ClientDataSetFeedsP.Value / RapMS;
3876
      if not ClientDataSetFeedsPd.IsNull
3877
      then
3878
        ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value / RapMS;
3879
    end;
3880
  end;
3881
  // Rapports
3882
  if ClientDataSetFeedsEDc.IsNull or ClientDataSetFeedsEB.IsNull or (ClientDataSetFeedsEB.Value = 0)
3883
  then
3884
    ClientDataSetFeedsdEc.Clear
3885
  else
3886
    ClientDataSetFeedsdEc.Value := ClientDataSetFeedsEDc.Value / ClientDataSetFeedsEB.Value * 100;
3887
  if ClientDataSetFeedsEMc.IsNull or ClientDataSetFeedsEDc.IsNull or (ClientDataSetFeedsEDc.Value = 0)
3888
  then
3889
    ClientDataSetFeedsEMc_EDc.Clear
3890
  else
3891
    ClientDataSetFeedsEMc_EDc.Value := ClientDataSetFeedsEMc.Value / ClientDataSetFeedsEDc.Value * 100;
3892
  if ClientDataSetFeedsENc.IsNull or ClientDataSetFeedsEMc.IsNull or (ClientDataSetFeedsEMc.Value = 0)
3893
  then
3894
    ClientDataSetFeedsENc_EMc.Clear
3895
  else
3896
    ClientDataSetFeedsENc_EMc.Value := ClientDataSetFeedsENc.Value / ClientDataSetFeedsEMc.Value * 100;
3897
  if ClientDataSetFeedsEDt.IsNull or ClientDataSetFeedsEB.IsNull or (ClientDataSetFeedsEB.Value = 0)
3898
  then
3899
    ClientDataSetFeedsdEt.Clear
3900
  else
3901
    ClientDataSetFeedsdEt.Value := ClientDataSetFeedsEDt.Value / ClientDataSetFeedsEB.Value * 100;
3902
  if ClientDataSetFeedsEMt.IsNull or ClientDataSetFeedsEDt.IsNull or (ClientDataSetFeedsEDt.Value = 0)
3903
  then
3904
    ClientDataSetFeedsEMt_EDt.Clear
3905
  else
3906
    ClientDataSetFeedsEMt_EDt.Value := ClientDataSetFeedsEMt.Value / ClientDataSetFeedsEDt.Value * 100;
3907
  if ClientDataSetFeedsENt.IsNull or ClientDataSetFeedsEMt.IsNull or (ClientDataSetFeedsEMt.Value = 0)
3908
  then
3909
    ClientDataSetFeedsENt_EMt.Clear
3910
  else
3911
    ClientDataSetFeedsENt_EMt.Value := ClientDataSetFeedsENt.Value / ClientDataSetFeedsEMt.Value * 100;
3912
  if ClientDataSetFeedsBonusC.Value <> 0
3913
  then // Prise en compte du bonus (porc croissance)
3914
  begin
3915
    if not ClientDataSetFeedsdEc.IsNull
3916
    then
3917
      ClientDataSetFeedsdEc.Value := ClientDataSetFeedsdEc.Value + ClientDataSetFeedsBonusC.Value;
3918
    if not ClientDataSetFeedsEB.IsNull and not ClientDataSetFeedsdEc.IsNull
3919
    then
3920
      ClientDataSetFeedsEDc.Value := ClientDataSetFeedsEB.Value * ClientDataSetFeedsdEc.Value / 100;
3921
    if not ClientDataSetFeedsEDc.IsNull and not ClientDataSetFeedsEMc_EDc.IsNull
3922
    then
3923
      ClientDataSetFeedsEMc.Value := ClientDataSetFeedsEDc.Value * ClientDataSetFeedsEMc_EDc.Value / 100;
3924
    if not ClientDataSetFeedsEMc.IsNull and not ClientDataSetFeedsENc_EMc.IsNull
3925
    then
3926
      ClientDataSetFeedsENc.Value := ClientDataSetFeedsEMc.Value * ClientDataSetFeedsENc_EMc.Value / 100;
3927
  end;
3928
  if ClientDataSetFeedsBonusT.Value <> 0
3929
  then // Prise en compte du bonus (porce adulte)
3930
  begin
3931
    if not ClientDataSetFeedsdEt.IsNull
3932
    then
3933
      ClientDataSetFeedsdEt.Value := ClientDataSetFeedsdEt.Value + ClientDataSetFeedsBonusT.Value;
3934
    if not ClientDataSetFeedsEB.IsNull and not ClientDataSetFeedsdEt.IsNull
3935
    then
3936
      ClientDataSetFeedsEDt.Value := ClientDataSetFeedsEB.Value * ClientDataSetFeedsdEt.Value / 100;
3937
    if not ClientDataSetFeedsEDt.IsNull and not ClientDataSetFeedsEMt_EDt.IsNull
3938
    then
3939
      ClientDataSetFeedsEMt.Value := ClientDataSetFeedsEDt.Value * ClientDataSetFeedsEMt_EDt.Value / 100;
3940
    if not ClientDataSetFeedsEMt.IsNull and not ClientDataSetFeedsENt_EMt.IsNull
3941
    then
3942
      ClientDataSetFeedsENt.Value := ClientDataSetFeedsEMt.Value * ClientDataSetFeedsENt_EMt.Value / 100;
3943
  end;
3944
  if ClientDataSetFeedsEDt.IsNull or ClientDataSetFeedsEDc.IsNull or (ClientDataSetFeedsEDc.Value = 0)
3945
  then
3946
    ClientDataSetFeedsEDt_EDc.Clear
3947
  else
3948
    ClientDataSetFeedsEDt_EDc.Value := ClientDataSetFeedsEDt.Value / ClientDataSetFeedsEDc.Value * 100;
3949
  if ClientDataSetFeedsEMt.IsNull or ClientDataSetFeedsEMc.IsNull or (ClientDataSetFeedsEMc.Value = 0)
3950
  then
3951
    ClientDataSetFeedsEMt_EMc.Clear
3952
  else
3953
    ClientDataSetFeedsEMt_EMc.Value := ClientDataSetFeedsEMt.Value / ClientDataSetFeedsEMc.Value * 100;
3954
  if ClientDataSetFeedsENt.IsNull or ClientDataSetFeedsENc.IsNull or (ClientDataSetFeedsENc.Value = 0)
3955
  then
3956
    ClientDataSetFeedsENt_ENc.Clear
3957
  else
3958
    ClientDataSetFeedsENt_ENc.Value := ClientDataSetFeedsENt.Value / ClientDataSetFeedsENc.Value * 100;
3959
  if not ClientDataSetFeedsdNc.IsNull
3960
  then
3961
    if ClientDataSetFeedsMAT.IsNull or (ClientDataSetFeedsMAT.Value = 0)
3962
    then
3963
      ClientDataSetFeedsdNc.Clear
3964
    else // dN = MATd / MAT
3965
      ClientDataSetFeedsdNc.Value := ClientDataSetFeedsdNc.Value / ClientDataSetFeedsMAT.Value * 100;
3966
  if not ClientDataSetFeedsdNt.IsNull
3967
  then
3968
    if ClientDataSetFeedsMAT.IsNull or (ClientDataSetFeedsMAT.Value = 0)
3969
    then
3970
      ClientDataSetFeedsdNt.Clear
3971
    else // dN = MATd / MAT
3972
      ClientDataSetFeedsdNt.Value := ClientDataSetFeedsdNt.Value / ClientDataSetFeedsMAT.Value * 100;
3973
  if ClientDataSetFeedsLysd.IsNull or ClientDataSetFeedsENc.IsNull or (ClientDataSetFeedsENc.Value = 0)
3974
  then
3975
    ClientDataSetFeedsLysd_ENc.Clear
3976
  else
3977
    if FormOptions.Energy = 0
3978
    then // g/MJ
3979
      if FormOptions.AA = 0
3980
      then // % (conversion)
3981
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value
3982
      else // g/kg
3983
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENc.Value
3984
    else // g/1000kcal
3985
      if FormOptions.AA = 0
3986
      then // % (conversion)
3987
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value * 1000
3988
      else // g/kg
3989
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENc.Value * 1000;
3990
  if ClientDataSetFeedsLysd.IsNull or ClientDataSetFeedsENt.IsNull or (ClientDataSetFeedsENt.Value = 0)
3991
  then
3992
    ClientDataSetFeedsLysd_ENt.Clear
3993
  else
3994
    if FormOptions.Energy = 0
3995
    then // g/MJ
3996
      if FormOptions.AA = 0
3997
      then // % (conversion)
3998
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value
3999
      else // g/kg
4000
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENt.Value
4001
    else // g/1000kcal
4002
      if FormOptions.AA = 0
4003
      then // % (conversion)
4004
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value * 1000
4005
      else // g/kg
4006
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENt.Value * 1000;
4007
  if ClientDataSetFeedsCa.IsNull or ClientDataSetFeedsPd.IsNull or (ClientDataSetFeedsPd.Value = 0)
4008
  then
4009
    ClientDataSetFeedsCa_Pd.Clear
4010
  else
4011
    ClientDataSetFeedsCa_Pd.Value := ClientDataSetFeedsCa.Value / ClientDataSetFeedsPd.Value;
4012
  if ClientDataSetFeedsPd.IsNull or ClientDataSetFeedsENc.IsNull or (ClientDataSetFeedsENc.Value = 0)
4013
  then
4014
    ClientDataSetFeedsPd_ENc.Clear
4015
  else
4016
    if FormOptions.Energy = 0
4017
    then // g/MJ
4018
      if FormOptions.Minerals = 0
4019
      then // % (conversion)
4020
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value
4021
      else // g/kg
4022
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENc.Value
4023
    else // g/1000kcal
4024
      if FormOptions.Minerals = 0
4025
      then // % (conversion)
4026
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value * 1000
4027
      else // g/kg
4028
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENc.Value * 1000;
4029
  if ClientDataSetFeedsPd.IsNull or ClientDataSetFeedsENt.IsNull or (ClientDataSetFeedsENt.Value = 0)
4030
  then
4031
    ClientDataSetFeedsPd_ENt.Clear
4032
  else
4033
    if FormOptions.Energy = 0
4034
    then // g/MJ
4035
      if FormOptions.Minerals = 0
4036
      then // % (conversion)
4037
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value
4038
      else // g/kg
4039
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENt.Value
4040
    else // g/1000 kcal
4041
      if FormOptions.Minerals = 0
4042
      then // % (conversion)
4043
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value * 1000
4044
      else // g/kg
4045
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENt.Value * 1000;
4046
  if ClientDataSetFeedsThrd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4047
  then
4048
    ClientDataSetFeedsThrd_Lysd.Clear
4049
  else
4050
    ClientDataSetFeedsThrd_Lysd.Value := ClientDataSetFeedsThrd.Value / ClientDataSetFeedsLysd.Value * 100;
4051
  if ClientDataSetFeedsMetd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4052
  then
4053
    ClientDataSetFeedsMetd_Lysd.Clear
4054
  else
4055
    ClientDataSetFeedsMetd_Lysd.Value := ClientDataSetFeedsMetd.Value / ClientDataSetFeedsLysd.Value * 100;
4056
  if ClientDataSetFeedsCysd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4057
  then
4058
    ClientDataSetFeedsCysd_Lysd.Clear
4059
  else
4060
    ClientDataSetFeedsCysd_Lysd.Value := ClientDataSetFeedsCysd.Value / ClientDataSetFeedsLysd.Value * 100;
4061
  if ClientDataSetFeedsMetCysd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4062
  then
4063
    ClientDataSetFeedsMetCysd_Lysd.Clear
4064
  else
4065
    ClientDataSetFeedsMetCysd_Lysd.Value := ClientDataSetFeedsMetCysd.Value / ClientDataSetFeedsLysd.Value * 100;
4066
  if ClientDataSetFeedsTrpd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4067
  then
4068
    ClientDataSetFeedsTrpd_Lysd.Clear
4069
  else
4070
    ClientDataSetFeedsTrpd_Lysd.Value := ClientDataSetFeedsTrpd.Value / ClientDataSetFeedsLysd.Value * 100;
4071
  if ClientDataSetFeedsIled.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4072
  then
4073
    ClientDataSetFeedsIled_Lysd.Clear
4074
  else
4075
    ClientDataSetFeedsIled_Lysd.Value := ClientDataSetFeedsIled.Value / ClientDataSetFeedsLysd.Value * 100;
4076
  if ClientDataSetFeedsVald.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4077
  then
4078
    ClientDataSetFeedsVald_Lysd.Clear
4079
  else
4080
    ClientDataSetFeedsVald_Lysd.Value := ClientDataSetFeedsVald.Value / ClientDataSetFeedsLysd.Value * 100;
4081
  if ClientDataSetFeedsLeud.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4082
  then
4083
    ClientDataSetFeedsLeud_Lysd.Clear
4084
  else
4085
    ClientDataSetFeedsLeud_Lysd.Value := ClientDataSetFeedsLeud.Value / ClientDataSetFeedsLysd.Value * 100;
4086
  if ClientDataSetFeedsPhed.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4087
  then
4088
    ClientDataSetFeedsPhed_Lysd.Clear
4089
  else
4090
    ClientDataSetFeedsPhed_Lysd.Value := ClientDataSetFeedsPhed.Value / ClientDataSetFeedsLysd.Value * 100;
4091
  if ClientDataSetFeedsTyrd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4092
  then
4093
    ClientDataSetFeedsTyrd_Lysd.Clear
4094
  else
4095
    ClientDataSetFeedsTyrd_Lysd.Value := ClientDataSetFeedsTyrd.Value / ClientDataSetFeedsLysd.Value * 100;
4096
  if ClientDataSetFeedsPheTyrd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4097
  then
4098
    ClientDataSetFeedsPheTyrd_Lysd.Clear
4099
  else
4100
    ClientDataSetFeedsPheTyrd_Lysd.Value := ClientDataSetFeedsPheTyrd.Value / ClientDataSetFeedsLysd.Value * 100;
4101
  if ClientDataSetFeedsHisd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4102
  then
4103
    ClientDataSetFeedsHisd_Lysd.Clear
4104
  else
4105
    ClientDataSetFeedsHisd_Lysd.Value := ClientDataSetFeedsHisd.Value / ClientDataSetFeedsLysd.Value * 100;
4106
  if ClientDataSetFeedsArgd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4107
  then
4108
    ClientDataSetFeedsArgd_Lysd.Clear
4109
  else
4110
    ClientDataSetFeedsArgd_Lysd.Value := ClientDataSetFeedsArgd.Value / ClientDataSetFeedsLysd.Value * 100;
4111
  if ClientDataSetFeedsAlad.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4112
  then
4113
    ClientDataSetFeedsAlad_Lysd.Clear
4114
  else
4115
    ClientDataSetFeedsAlad_Lysd.Value := ClientDataSetFeedsAlad.Value / ClientDataSetFeedsLysd.Value * 100;
4116
  if ClientDataSetFeedsAspd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4117
  then
4118
    ClientDataSetFeedsAspd_Lysd.Clear
4119
  else
4120
    ClientDataSetFeedsAspd_Lysd.Value := ClientDataSetFeedsAspd.Value / ClientDataSetFeedsLysd.Value * 100;
4121
  if ClientDataSetFeedsGlud.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4122
  then
4123
    ClientDataSetFeedsGlud_Lysd.Clear
4124
  else
4125
    ClientDataSetFeedsGlud_Lysd.Value := ClientDataSetFeedsGlud.Value / ClientDataSetFeedsLysd.Value * 100;
4126
  if ClientDataSetFeedsGlyd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4127
  then
4128
    ClientDataSetFeedsGlyd_Lysd.Clear
4129
  else
4130
    ClientDataSetFeedsGlyd_Lysd.Value := ClientDataSetFeedsGlyd.Value / ClientDataSetFeedsLysd.Value * 100;
4131
  if ClientDataSetFeedsSerd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4132
  then
4133
    ClientDataSetFeedsSerd_Lysd.Clear
4134
  else
4135
    ClientDataSetFeedsSerd_Lysd.Value := ClientDataSetFeedsSerd.Value / ClientDataSetFeedsLysd.Value * 100;
4136
  if ClientDataSetFeedsProd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4137
  then
4138
    ClientDataSetFeedsProd_Lysd.Clear
4139
  else
4140
    ClientDataSetFeedsProd_Lysd.Value := ClientDataSetFeedsProd.Value / ClientDataSetFeedsLysd.Value * 100;
4141
end;
4142
4143
procedure TDataModuleDeclaration.AggregateLevelSumUpdate(Agg: TAggregate);
4144
begin
4145
  if not ClientDataSetFeeds.Eof
4146
  then
4147
  begin
4148
    ClientDataSetFeeds.Edit;
4149
    if VarIsEmpty(Agg.Value) or VarIsNull(Agg.Value)
4150
    then
4151
      ClientDataSetFeedsLevelSum.Clear
4152
    else
4153
      ClientDataSetFeedsLevelSum.AsFloat := Agg.Value;
4154
    ClientDataSetFeeds.Post;
4155
  end;
4156
end;
4157
4158
procedure TDataModuleDeclaration.ClientDataSetFeedsCalcFields(DataSet: TDataSet);
4159
begin
4160
  if ClientDataSetFeedsPhytaseIncorporation.IsNull or ClientDataSetFeedsPhytaseConcentration.IsNull
4161
  or (ClientDataSetFeedsPhytaseConcentration.Value = 0)
4162
  then
4163
    ClientDataSetFeedsPhytaseLevel.Clear
4164
  else
4165
    ClientDataSetFeedsPhytaseLevel.Value := OutputIncorporation(ClientDataSetFeedsPhytaseIncorporation.Value / ClientDataSetFeedsPhytaseConcentration.Value / 1000, FormOptions.Incorporation);
4166
  ClientDataSetFeedsTotal.Value := ClientDataSetFeedsLevelSum.Value + ClientDataSetFeedsPhytaseLevel.Value;
4167
  ClientDataSetFeedsRemain.Value := OutputIncorporation(1, FormOptions.Incorporation) - ClientDataSetFeedsTotal.Value;
4168
end;
4169
4170
procedure TDataModuleDeclaration.ClientDataSetIngredientsFilterRecord(DataSet: TDataSet; var Accept: Boolean);
4171
begin
4172
  Accept := True;
4173
  if FilterOnClass and (FilteredClass > 0)
4174
  then
4175
    Accept := Accept and (DataSet.FieldByName('Class').AsInteger = FilteredClass);
4176
  if FilterOnDatabase
4177
  then
4178
    case FilteredDatabase of
4179
      1: // User database
4180
        Accept := Accept and DataSet.FieldByName('User').AsBoolean;
4181
      2: // Reference tables
4182
        Accept := Accept and not DataSet.FieldByName('User').AsBoolean;
4183
    end;
4184
  if FilterOnName and (FilteredName <> '')
4185
  then
4186
    Accept := Accept and (Pos(FilteredName, DataSet.FieldByName('Name').AsWideString) > 0);
4187
end;
4188
4189
procedure TDataModuleDeclaration.DataModuleCreate(Sender: TObject);
4190
var
4191
  i: Integer;
4192
  ExeDir, DataDir, DataFile: String;
4193
  Cryptage: TLbBlowfish;
4194
  FluxClair, FluxCrypte: TMemoryStream;
4195
  DocumentsPath: array[0..MAX_PATH] of Char;
4196
begin
4197
  // Classes
4198
  ClassList := TStringList.Create;
4199
  ClassList.Add('Cereals');
4200
  ClassList.Add('Wheat by-products');
4201
  ClassList.Add('Maize by-products');
4202
  ClassList.Add('Other cereal by-products');
4203
  ClassList.Add('Rice by-products');
4204
  ClassList.Add('Legume and oil seeds');
4205
  ClassList.Add('Oil seed meals');
4206
  ClassList.Add('Starch, roots and tubers');
4207
  ClassList.Add('Fruits and vegetables by-products');
4208
  ClassList.Add('Molasses and vinasses');
4209
  ClassList.Add('Other plant products');
4210
  ClassList.Add('Dehydrated forages');
4211
  ClassList.Add('Dairy products');
4212
  ClassList.Add('Fish meals and solubles');
4213
  ClassList.Add('Other animal by-products');
4214
  ClassList.Add('Fats and oils');
4215
  ClassList.Add('Amino acids');
4216
  ClassList.Add('Mineral sources');
4217
  ClassList.Add('Not referenced');
4218
  ClientDataSetClasses.CreateDataSet;
4219
  for i := 0 to ClassList.Count - 1 do
4220
    ClientDataSetClasses.AppendRecord([i + 1, dgettext('InraAfz', ClassList[i])]);
4221
  // Phytase
4222
  ClientDataSetPhytase.CreateDataSet;
4223
  ClientDataSetPhytase.AppendRecord([1, 0.60, 0.67]);
4224
  ClientDataSetPhytase.AppendRecord([2, 0.65, 0.76]);
4225
  ClientDataSetPhytase.AppendRecord([3, 0.70, 0.87]);
4226
  ClientDataSetPhytase.AppendRecord([4, 0.75, 1.00]);
4227
  ClientDataSetPhytase.AppendRecord([5, 0.80, 1.15]);
4228
  ClientDataSetPhytase.AppendRecord([6, 0.85, 1.34]);
4229
  ClientDataSetPhytase.AppendRecord([7, 0.90, 1.60]);
4230
  ClientDataSetPhytase.AppendRecord([8, 0.95, 1.98]);
4231
  // Tables de r?f?rence
4232
  ExeDir := ExtractFilePath(Application.ExeName);
4233
  DataFile := ExeDir + 'EvaPig2020.dat';
4234
  if not FileExists(DataFile)
4235
  then // Erreur
4236
  begin
4237
    MessageDlg(_('Reference tables of composition and nutritional values of feed materials for pigs') + sLineBreak
4238
      + Format(_('%s: file not found'), [DataFile]), mtError, [mbOK], 0);
4239
    Application.Terminate;
4240
    Exit;
4241
  end;
4242
  ClientDataSetInraAfz.CreateDataSet;
4243
  Cryptage := TlbBlowfish.Create(nil);
4244
  Cryptage.GenerateKey('Tables of Composition and Nutritional Value of Feed Materials');
4245
  FluxCrypte := TMemoryStream.Create;
4246
  FluxClair := TMemoryStream.Create;
4247
  try
4248
    FluxCrypte.LoadFromFile(DataFile);
4249
    FluxCrypte.Position := 0;
4250
    Cryptage.DecryptStream(FluxCrypte, FluxClair);
4251
    FluxClair.Position := 0;
4252
    try
4253
      ClientDataSetInraAfz.LoadFromStream(FluxClair);
4254
    except
4255
      MessageDlg(_('Reference tables of composition and nutritional values of feed materials for pigs') + sLineBreak
4256
        + _('Invalid data format'), mtError, [mbOK], 0);
4257
      Application.Terminate;
4258
      Exit;
4259
    end;
4260
  finally
4261
    FluxCrypte.Free;
4262
    FluxClair.Free;
4263
    Cryptage.Free;
4264
  end;
4265
  // Base User.sqb
4266
  SHGetFolderPath(0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, DocumentsPath);
4267
  DataDir := IncludeTrailingPathDelimiter(IncludeTrailingPathDelimiter(DocumentsPath) + Application.Title);
4268
  ForceDirectories(DataDir);
4269
  if not FileExists(ExeDir + 'sqlite3.dll')
4270
  then // Erreur
4271
  begin
4272
    MessageDlg(_('SQLite') + sLineBreak
4273
      + Format(_('%s: driver missing'), [ExeDir + 'sqlite3.dll']), mtError, [mbOK], 0);
4274
    Application.Terminate;
4275
    Exit;
4276
  end;
4277
  DBUser := TSQLiteDatabase.Create(DataDir + 'User.sqb');
4278
  if not DBUser.TableExists('Ingredients')
4279
  then // Cr?ation de la table Ingredients
4280
  begin
4281
    DBUser.ExecSQL('CREATE TABLE Ingredients ('
4282
      + 'Id INTEGER PRIMARY KEY, '
4283
      + 'Name TEXT, '
4284
      + 'Definition TEXT, '
4285
      + 'Class INTEGER, '
4286
      + 'Model INTEGER, '
4287
      + 'MS REAL, '
4288
      + 'MM REAL, '
4289
      + 'MAT REAL, '
4290
      + 'MG REAL, '
4291
      + 'CB REAL, '
4292
      + 'NDF REAL, '
4293
      + 'ADF REAL, '
4294
      + 'ADL REAL, '
4295
      + 'Amidon REAL, '
4296
      + 'Sucres REAL, '
4297
      + 'EB REAL, '
4298
      + 'Bonus REAL, '
4299
      + 'Lys REAL, '
4300
      + 'Thr REAL, '
4301
      + 'Met REAL, '
4302
      + 'Cys REAL, '
4303
      + 'MetCys REAL, '
4304
      + 'Trp REAL, '
4305
      + 'Ile REAL, '
4306
      + 'Val REAL, '
4307
      + 'Leu REAL, '
4308
      + 'Phe REAL, '
4309
      + 'Tyr REAL, '
4310
      + 'PheTyr REAL, '
4311
      + 'His REAL, '
4312
      + 'Arg REAL, '
4313
      + 'Ala REAL, '
4314
      + 'Asp REAL, '
4315
      + 'Glu REAL, '
4316
      + 'Gly REAL, '
4317
      + 'Ser REAL, '
4318
      + 'Pro REAL, '
4319
      + 'dLys REAL, '
4320
      + 'dThr REAL, '
4321
      + 'dMet REAL, '
4322
      + 'dCys REAL, '
4323
      + 'dMetCys REAL, '
4324
      + 'dTrp REAL, '
4325
      + 'dIle REAL, '
4326
      + 'dVal REAL, '
4327
      + 'dLeu REAL, '
4328
      + 'dPhe REAL, '
4329
      + 'dTyr REAL, '
4330
      + 'dPheTyr REAL, '
4331
      + 'dHis REAL, '
4332
      + 'dArg REAL, '
4333
      + 'dAla REAL, '
4334
      + 'dAsp REAL, '
4335
      + 'dGlu REAL, '
4336
      + 'dGly REAL, '
4337
      + 'dSer REAL, '
4338
      + 'dPro REAL, '
4339
      + 'Ca REAL, '
4340
      + 'P REAL, '
4341
      + 'dP REAL, '
4342
      + 'dPphy REAL)');
4343
    DBUser.ExecSQL('CREATE INDEX IdxClasses ON Ingredients (Class)');
4344
    DBUser.ExecSQL('CREATE INDEX IdxModels ON Ingredients (Model)');
4345
  end;
4346
  if not DBUser.TableExists('Feeds')
4347
  then // Cr?ation de la table Feeds
4348
    DBUser.ExecSQL('CREATE TABLE Feeds ('
4349
      + 'Id INTEGER PRIMARY KEY, '
4350
      + 'Name TEXT, '
4351
      + 'Description TEXT, '
4352
      + 'Presentation INTEGER, '
4353
      + 'BonusC REAL, '
4354
      + 'BonusT REAL, '
4355
      + 'Phytase INTEGER, '
4356
      + 'Concentration REAL, '
4357
      + 'Incorporation REAL)');
4358
  if not DBUser.TableExists('Composition')
4359
  then // Cr?ation de la table Composition
4360
  begin
4361
    DBUser.ExecSQL('CREATE TABLE Composition ('
4362
      + 'Feed INTEGER, '
4363
      + 'Ingredient INTEGER, '
4364
      + 'User BOOLEAN, '
4365
      + 'Rank INTEGER, '
4366
      + 'MS REAL, '
4367
      + 'Level REAL)');
4368
    DBUser.ExecSQL('CREATE INDEX IdxFeeds ON Composition (Feed)');
4369
    DBUser.ExecSQL('CREATE INDEX IdxIngredients ON Composition (Ingredient)');
4370
  end;
4371
  Application.ProcessMessages;
4372
  // Liste des mati?res premi?res utilisateur
4373
  UserList := TStringList.Create;
4374
  TableIngredients := DBUser.GetTable('SELECT Name FROM Ingredients');
4375
  with TableIngredients do
4376
    try
4377
      while not Eof do
4378
      begin
4379
        UserList.Add(FieldAsString(FieldIndex['Name']));
4380
        Next;
4381
      end;
4382
    finally
4383
      Free;
4384
    end;
4385
  // Liste des r?gimes
4386
  FeedList := TStringList.Create;
4387
  TableFeeds := DBUser.GetTable('SELECT Name FROM Feeds');
4388
  with TableFeeds do
4389
    try
4390
      while not Eof do
4391
      begin
4392
        FeedList.Add(FieldAsString(FieldIndex['Name']));
4393
        Next;
4394
      end;
4395
    finally
4396
      Free;
4397
    end;
4398
end;
4399
4400
procedure TDataModuleDeclaration.DataModuleDestroy(Sender: TObject);
4401
begin
4402
  ClientDataSetClasses.Close;
4403
  ClientDataSetPhytase.Close;
4404
  ClientDataSetInraAfz.Close;
4405
  ClassList.Free;
4406
  UserList.Free;
4407
  FeedList.Free;
4408
  Application.ProcessMessages;
4409
  DBUser.ExecSQL('VACUUM'); // Compacter la base User.sqb
4410
  DBUser.Free;
4411
  Application.ProcessMessages;
4412
end;
4413
4414
function TDataModuleDeclaration.InputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
4415
begin
4416
  if ProximalUnit = 0
4417
  then // %
4418
    Result := Value / 100
4419
  else // g/kg
4420
    Result := Value / 1000;
4421
  if ExpressionMode = 0
4422
  then // sur frais
4423
    Result := Result / MS;
4424
end;
4425
4426
function TDataModuleDeclaration.InputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
4427
begin
4428
  if EnergyUnit = 0
4429
  then // MJ/kg
4430
    Result := Value
4431
  else // kcal/kg
4432
    Result := Value * CALORIE / 1000;
4433
  if ExpressionMode = 0
4434
  then // sur frais
4435
    Result := Result / MS;
4436
end;
4437
4438
function TDataModuleDeclaration.InputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
4439
begin
4440
  if AAUnit = 0
4441
  then // %
4442
    Result := Value / MAT / 100
4443
  else // g/kg
4444
    Result := Value / MAT / 1000;
4445
  if ExpressionMode = 0
4446
  then // sur frais
4447
    Result := Result / MS;
4448
end;
4449
4450
function TDataModuleDeclaration.InputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
4451
begin
4452
  if MineralsUnit = 0
4453
  then // %
4454
    Result := Value / 100
4455
  else // g/kg
4456
    Result := Value / 1000;
4457
  if ExpressionMode = 0
4458
  then // sur frais
4459
    Result := Result / MS;
4460
end;
4461
4462
function TDataModuleDeclaration.InputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
4463
begin
4464
  if IncorporationUnit = 0
4465
  then // %
4466
    Result := Value / 100
4467
  else // g/kg
4468
    Result := Value / 1000;
4469
end;
4470
4471
function TDataModuleDeclaration.OutputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
4472
begin
4473
  if ProximalUnit = 0
4474
  then // %
4475
    Result := Value * 100
4476
  else // g/kg
4477
    Result := Value * 1000;
4478
  if ExpressionMode = 0
4479
  then // sur frais
4480
    Result := Result * MS;
4481
end;
4482
4483
function TDataModuleDeclaration.OutputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
4484
begin
4485
  if EnergyUnit = 0
4486
  then // MJ/kg
4487
    Result := Value
4488
  else // kcal/kg
4489
    Result := Value / CALORIE * 1000;
4490
  if ExpressionMode = 0
4491
  then // sur frais
4492
    Result := Result * MS;
4493
end;
4494
4495
function TDataModuleDeclaration.OutputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
4496
begin
4497
  if AAUnit = 0
4498
  then // %
4499
    Result := Value * MAT * 100
4500
  else // g/kg
4501
    Result := Value * MAT * 1000;
4502
  if ExpressionMode = 0
4503
  then // sur frais
4504
    Result := Result * MS;
4505
end;
4506
4507
function TDataModuleDeclaration.OutputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
4508
begin
4509
  if MineralsUnit = 0
4510
  then // %
4511
    Result := Value * 100
4512
  else // g/kg
4513
    Result := Value * 1000;
4514
  if ExpressionMode = 0
4515
  then // sur frais
4516
    Result := Result * MS;
4517
end;
4518
4519
function TDataModuleDeclaration.OutputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
4520
begin
4521
  if IncorporationUnit = 0
4522
  then // %
4523
    Result := Value * 100
4524
  else // g/kg
4525
    Result := Value * 1000;
4526
end;
4527
4528
function TDataModuleDeclaration.StrTrunc(S: String; Max: Integer): String;
4529
var
4530
  l, r: Integer;
4531
begin
4532
  if ElementToCharLen(S, Length(S)) > Max
4533
  then // Cut string S to Max chars
4534
  begin
4535
    l := Max div 2;
4536
    r := Max - l - 3;
4537
    Result := AnsiLeftStr(S, l) + '...' + AnsiRightStr(S, r);
4538
  end
4539
  else
4540
    Result := S;
4541
end;
4542
4543
end.