Statistiques
| Révision:

root / UnitDeclaration.pas @ 5

Historique | Voir | Annoter | Télécharger (212,244 ko)

1
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
    ClientDataSetInraAfzComment: TStringField;
46
    ClientDataSetInraAfzSource: TStringField;
47
    ClientDataSetInraAfzClass: TIntegerField;
48
    ClientDataSetInraAfzMS: TFloatField;
49
    ClientDataSetInraAfzMM: TFloatField;
50
    ClientDataSetInraAfzMAT: TFloatField;
51
    ClientDataSetInraAfzMG: TFloatField;
52
    ClientDataSetInraAfzCB: TFloatField;
53
    ClientDataSetInraAfzCoefCB: TFloatField;
54
    ClientDataSetInraAfzNDF: TFloatField;
55
    ClientDataSetInraAfzCoefNDF: TFloatField;
56
    ClientDataSetInraAfzADF: TFloatField;
57
    ClientDataSetInraAfzCoefADF: TFloatField;
58
    ClientDataSetInraAfzADL: TFloatField;
59
    ClientDataSetInraAfzAmidon: TFloatField;
60
    ClientDataSetInraAfzSucres: TFloatField;
61
    ClientDataSetInraAfzEB: TFloatField;
62
    ClientDataSetInraAfzdEc: TFloatField;
63
    ClientDataSetInraAfzEMc_EDc: TFloatField;
64
    ClientDataSetInraAfzENc_EMc: TFloatField;
65
    ClientDataSetInraAfzEMt_EDt: TFloatField;
66
    ClientDataSetInraAfzENt_EMt: TFloatField;
67
    ClientDataSetInraAfzEDt_EDc: TFloatField;
68
    ClientDataSetInraAfza: TFloatField;
69
    ClientDataSetInraAfzb: TFloatField;
70
    ClientDataSetInraAfzdNc: TFloatField;
71
    ClientDataSetInraAfzdNt: TFloatField;
72
    ClientDataSetInraAfzLys: TFloatField;
73
    ClientDataSetInraAfzThr: TFloatField;
74
    ClientDataSetInraAfzMet: TFloatField;
75
    ClientDataSetInraAfzCys: TFloatField;
76
    ClientDataSetInraAfzMetCys: TFloatField;
77
    ClientDataSetInraAfzTrp: TFloatField;
78
    ClientDataSetInraAfzIle: TFloatField;
79
    ClientDataSetInraAfzVal: TFloatField;
80
    ClientDataSetInraAfzLeu: TFloatField;
81
    ClientDataSetInraAfzPhe: TFloatField;
82
    ClientDataSetInraAfzTyr: TFloatField;
83
    ClientDataSetInraAfzPheTyr: TFloatField;
84
    ClientDataSetInraAfzHis: TFloatField;
85
    ClientDataSetInraAfzArg: TFloatField;
86
    ClientDataSetInraAfzAla: TFloatField;
87
    ClientDataSetInraAfzAsp: TFloatField;
88
    ClientDataSetInraAfzGlu: TFloatField;
89
    ClientDataSetInraAfzGly: TFloatField;
90
    ClientDataSetInraAfzSer: TFloatField;
91
    ClientDataSetInraAfzPro: TFloatField;
92
    ClientDataSetInraAfzdLys: TFloatField;
93
    ClientDataSetInraAfzdThr: TFloatField;
94
    ClientDataSetInraAfzdMet: TFloatField;
95
    ClientDataSetInraAfzdCys: TFloatField;
96
    ClientDataSetInraAfzdMetCys: TFloatField;
97
    ClientDataSetInraAfzdTrp: TFloatField;
98
    ClientDataSetInraAfzdIle: TFloatField;
99
    ClientDataSetInraAfzdVal: TFloatField;
100
    ClientDataSetInraAfzdLeu: TFloatField;
101
    ClientDataSetInraAfzdPhe: TFloatField;
102
    ClientDataSetInraAfzdTyr: TFloatField;
103
    ClientDataSetInraAfzdPheTyr: TFloatField;
104
    ClientDataSetInraAfzdHis: TFloatField;
105
    ClientDataSetInraAfzdArg: TFloatField;
106
    ClientDataSetInraAfzdAla: TFloatField;
107
    ClientDataSetInraAfzdAsp: TFloatField;
108
    ClientDataSetInraAfzdGlu: TFloatField;
109
    ClientDataSetInraAfzdGly: TFloatField;
110
    ClientDataSetInraAfzdSer: TFloatField;
111
    ClientDataSetInraAfzdPro: TFloatField;
112
    ClientDataSetInraAfzCa: TFloatField;
113
    ClientDataSetInraAfzP: TFloatField;
114
    ClientDataSetInraAfzdP: TFloatField;
115
    ClientDataSetInraAfzdPphy: TFloatField;
116
    ClientDataSetInraAfzNa: TFloatField;
117
    ClientDataSetInraAfzK: TFloatField;
118
    ClientDataSetInraAfzCl: TFloatField;
119
    DataSourceInraAfz: TDataSource;
120
    ClientDataSetIngredients: TClientDataSet;
121
    ClientDataSetIngredientsId: TIntegerField;
122
    ClientDataSetIngredientsName: TWideStringField;
123
    ClientDataSetIngredientsDefinition: TWideStringField;
124
    ClientDataSetIngredientsClass: TIntegerField;
125
    ClientDataSetIngredientsClassName: TWideStringField;
126
    ClientDataSetIngredientsUser: TBooleanField;
127
    ClientDataSetIngredientsModel: TIntegerField;
128
    ClientDataSetIngredientsSource: TWideStringField;
129
    ClientDataSetIngredientsMS: TFloatField;
130
    ClientDataSetIngredientsMS2: TFloatField;
131
    ClientDataSetIngredientsMM: TFloatField;
132
    ClientDataSetIngredientsMAT: TFloatField;
133
    ClientDataSetIngredientsMG: TFloatField;
134
    ClientDataSetIngredientsCB: TFloatField;
135
    ClientDataSetIngredientsNDF: TFloatField;
136
    ClientDataSetIngredientsADF: TFloatField;
137
    ClientDataSetIngredientsADL: TFloatField;
138
    ClientDataSetIngredientsAmidon: TFloatField;
139
    ClientDataSetIngredientsSucres: TFloatField;
140
    ClientDataSetIngredientsEB: TFloatField;
141
    ClientDataSetIngredientsBonus: TFloatField;
142
    ClientDataSetIngredientsdEc: TFloatField;
143
    ClientDataSetIngredientsEDc: TFloatField;
144
    ClientDataSetIngredientsEMc_EDc: TFloatField;
145
    ClientDataSetIngredientsEMc: TFloatField;
146
    ClientDataSetIngredientsENc_EMc: TFloatField;
147
    ClientDataSetIngredientsENc: TFloatField;
148
    ClientDataSetIngredientsdEt: TFloatField;
149
    ClientDataSetIngredientsEDt: TFloatField;
150
    ClientDataSetIngredientsEMt_EDt: TFloatField;
151
    ClientDataSetIngredientsEMt: TFloatField;
152
    ClientDataSetIngredientsENt_EMt: TFloatField;
153
    ClientDataSetIngredientsENt: TFloatField;
154
    ClientDataSetIngredientsEDt_EDc: TFloatField;
155
    ClientDataSetIngredientsEMt_EMc: TFloatField;
156
    ClientDataSetIngredientsENt_ENc: TFloatField;
157
    ClientDataSetIngredientsdNc: TFloatField;
158
    ClientDataSetIngredientsdNt: TFloatField;
159
    ClientDataSetIngredientsLys: TFloatField;
160
    ClientDataSetIngredientsThr: TFloatField;
161
    ClientDataSetIngredientsMet: TFloatField;
162
    ClientDataSetIngredientsCys: TFloatField;
163
    ClientDataSetIngredientsMetCys: TFloatField;
164
    ClientDataSetIngredientsTrp: TFloatField;
165
    ClientDataSetIngredientsIle: TFloatField;
166
    ClientDataSetIngredientsVal: TFloatField;
167
    ClientDataSetIngredientsLeu: TFloatField;
168
    ClientDataSetIngredientsPhe: TFloatField;
169
    ClientDataSetIngredientsTyr: TFloatField;
170
    ClientDataSetIngredientsPheTyr: TFloatField;
171
    ClientDataSetIngredientsHis: TFloatField;
172
    ClientDataSetIngredientsArg: TFloatField;
173
    ClientDataSetIngredientsAla: TFloatField;
174
    ClientDataSetIngredientsAsp: TFloatField;
175
    ClientDataSetIngredientsGlu: TFloatField;
176
    ClientDataSetIngredientsGly: TFloatField;
177
    ClientDataSetIngredientsSer: TFloatField;
178
    ClientDataSetIngredientsPro: TFloatField;
179
    ClientDataSetIngredientsLys_MAT: TFloatField;
180
    ClientDataSetIngredientsThr_MAT: TFloatField;
181
    ClientDataSetIngredientsMet_MAT: TFloatField;
182
    ClientDataSetIngredientsCys_MAT: TFloatField;
183
    ClientDataSetIngredientsMetCys_MAT: TFloatField;
184
    ClientDataSetIngredientsTrp_MAT: TFloatField;
185
    ClientDataSetIngredientsIle_MAT: TFloatField;
186
    ClientDataSetIngredientsVal_MAT: TFloatField;
187
    ClientDataSetIngredientsLeu_MAT: TFloatField;
188
    ClientDataSetIngredientsPhe_MAT: TFloatField;
189
    ClientDataSetIngredientsTyr_MAT: TFloatField;
190
    ClientDataSetIngredientsPheTyr_MAT: TFloatField;
191
    ClientDataSetIngredientsHis_MAT: TFloatField;
192
    ClientDataSetIngredientsArg_MAT: TFloatField;
193
    ClientDataSetIngredientsAla_MAT: TFloatField;
194
    ClientDataSetIngredientsAsp_MAT: TFloatField;
195
    ClientDataSetIngredientsGlu_MAT: TFloatField;
196
    ClientDataSetIngredientsGly_MAT: TFloatField;
197
    ClientDataSetIngredientsSer_MAT: TFloatField;
198
    ClientDataSetIngredientsPro_MAT: TFloatField;
199
    ClientDataSetIngredientsdLys: TFloatField;
200
    ClientDataSetIngredientsdThr: TFloatField;
201
    ClientDataSetIngredientsdMet: TFloatField;
202
    ClientDataSetIngredientsdCys: TFloatField;
203
    ClientDataSetIngredientsdMetCys: TFloatField;
204
    ClientDataSetIngredientsdTrp: TFloatField;
205
    ClientDataSetIngredientsdIle: TFloatField;
206
    ClientDataSetIngredientsdVal: TFloatField;
207
    ClientDataSetIngredientsdLeu: TFloatField;
208
    ClientDataSetIngredientsdPhe: TFloatField;
209
    ClientDataSetIngredientsdTyr: TFloatField;
210
    ClientDataSetIngredientsdPheTyr: TFloatField;
211
    ClientDataSetIngredientsdHis: TFloatField;
212
    ClientDataSetIngredientsdArg: TFloatField;
213
    ClientDataSetIngredientsdAla: TFloatField;
214
    ClientDataSetIngredientsdAsp: TFloatField;
215
    ClientDataSetIngredientsdGlu: TFloatField;
216
    ClientDataSetIngredientsdGly: TFloatField;
217
    ClientDataSetIngredientsdSer: TFloatField;
218
    ClientDataSetIngredientsdPro: TFloatField;
219
    ClientDataSetIngredientsLysd: TFloatField;
220
    ClientDataSetIngredientsThrd: TFloatField;
221
    ClientDataSetIngredientsMetd: TFloatField;
222
    ClientDataSetIngredientsCysd: TFloatField;
223
    ClientDataSetIngredientsMetCysd: TFloatField;
224
    ClientDataSetIngredientsTrpd: TFloatField;
225
    ClientDataSetIngredientsIled: TFloatField;
226
    ClientDataSetIngredientsVald: TFloatField;
227
    ClientDataSetIngredientsLeud: TFloatField;
228
    ClientDataSetIngredientsPhed: TFloatField;
229
    ClientDataSetIngredientsTyrd: TFloatField;
230
    ClientDataSetIngredientsPheTyrd: TFloatField;
231
    ClientDataSetIngredientsHisd: TFloatField;
232
    ClientDataSetIngredientsArgd: TFloatField;
233
    ClientDataSetIngredientsAlad: TFloatField;
234
    ClientDataSetIngredientsAspd: TFloatField;
235
    ClientDataSetIngredientsGlud: TFloatField;
236
    ClientDataSetIngredientsGlyd: TFloatField;
237
    ClientDataSetIngredientsSerd: TFloatField;
238
    ClientDataSetIngredientsProd: TFloatField;
239
    ClientDataSetIngredientsLysd_ENc: TFloatField;
240
    ClientDataSetIngredientsLysd_ENt: TFloatField;
241
    ClientDataSetIngredientsCa: TFloatField;
242
    ClientDataSetIngredientsP: TFloatField;
243
    ClientDataSetIngredientsdP: TFloatField;
244
    ClientDataSetIngredientsdPphy: TFloatField;
245
    ClientDataSetIngredientsNa: TFloatField;
246
    ClientDataSetIngredientsK: TFloatField;
247
    ClientDataSetIngredientsCl: TFloatField;
248
    ClientDataSetIngredientsBE: TFloatField;
249
    DataSourceIngredients: TDataSource;
250
    ClientDataSetComposition: TClientDataSet;
251
    ClientDataSetCompositionFeed: TIntegerField;
252
    ClientDataSetCompositionIngredient: TIntegerField;
253
    ClientDataSetCompositionUser: TBooleanField;
254
    ClientDataSetCompositionIngredientName: TWideStringField;
255
    ClientDataSetCompositionRank: TIntegerField;
256
    ClientDataSetCompositionMS: TFloatField;
257
    ClientDataSetCompositionLevel: TFloatField;
258
    DataSourceComposition: TDataSource;
259
    ClientDataSetPhytase: TClientDataSet;
260
    ClientDataSetPhytaseId: TAutoIncField;
261
    ClientDataSetPhytaseType: TFloatField;
262
    ClientDataSetPhytaseCoef: TFloatField;
263
    DataSourcePhytase: TDataSource;
264
    ClientDataSetFeeds: TClientDataSet;
265
    ClientDataSetFeedsId: TIntegerField;
266
    ClientDataSetFeedsName: TWideStringField;
267
    ClientDataSetFeedsDescription: TWideStringField;
268
    ClientDataSetFeedsPresentation: TIntegerField;
269
    ClientDataSetFeedsBonusC: TFloatField;
270
    ClientDataSetFeedsBonusT: TFloatField;
271
    ClientDataSetFeedsMS: TFloatField;
272
    ClientDataSetFeedsMS2: TFloatField;
273
    ClientDataSetFeedsMM: TFloatField;
274
    ClientDataSetFeedsMAT: TFloatField;
275
    ClientDataSetFeedsMG: TFloatField;
276
    ClientDataSetFeedsCB: TFloatField;
277
    ClientDataSetFeedsNDF: TFloatField;
278
    ClientDataSetFeedsADF: TFloatField;
279
    ClientDataSetFeedsADL: TFloatField;
280
    ClientDataSetFeedsAmidon: TFloatField;
281
    ClientDataSetFeedsSucres: TFloatField;
282
    ClientDataSetFeedsEB: TFloatField;
283
    ClientDataSetFeedsdEc: TFloatField;
284
    ClientDataSetFeedsEDc: TFloatField;
285
    ClientDataSetFeedsEMc_EDc: TFloatField;
286
    ClientDataSetFeedsEMc: TFloatField;
287
    ClientDataSetFeedsENc_EMc: TFloatField;
288
    ClientDataSetFeedsENc: TFloatField;
289
    ClientDataSetFeedsdEt: TFloatField;
290
    ClientDataSetFeedsEDt: TFloatField;
291
    ClientDataSetFeedsEMt_EDt: TFloatField;
292
    ClientDataSetFeedsEMt: TFloatField;
293
    ClientDataSetFeedsENt_EMt: TFloatField;
294
    ClientDataSetFeedsENt: TFloatField;
295
    ClientDataSetFeedsEDt_EDc: TFloatField;
296
    ClientDataSetFeedsEMt_EMc: TFloatField;
297
    ClientDataSetFeedsENt_ENc: TFloatField;
298
    ClientDataSetFeedsdNc: TFloatField;
299
    ClientDataSetFeedsdNt: TFloatField;
300
    ClientDataSetFeedsLys: TFloatField;
301
    ClientDataSetFeedsThr: TFloatField;
302
    ClientDataSetFeedsMet: TFloatField;
303
    ClientDataSetFeedsCys: TFloatField;
304
    ClientDataSetFeedsMetCys: TFloatField;
305
    ClientDataSetFeedsTrp: TFloatField;
306
    ClientDataSetFeedsIle: TFloatField;
307
    ClientDataSetFeedsVal: TFloatField;
308
    ClientDataSetFeedsLeu: TFloatField;
309
    ClientDataSetFeedsPhe: TFloatField;
310
    ClientDataSetFeedsTyr: TFloatField;
311
    ClientDataSetFeedsPheTyr: TFloatField;
312
    ClientDataSetFeedsHis: TFloatField;
313
    ClientDataSetFeedsArg: TFloatField;
314
    ClientDataSetFeedsAla: TFloatField;
315
    ClientDataSetFeedsAsp: TFloatField;
316
    ClientDataSetFeedsGlu: TFloatField;
317
    ClientDataSetFeedsGly: TFloatField;
318
    ClientDataSetFeedsSer: TFloatField;
319
    ClientDataSetFeedsPro: TFloatField;
320
    ClientDataSetFeedsLysd: TFloatField;
321
    ClientDataSetFeedsThrd: TFloatField;
322
    ClientDataSetFeedsMetd: TFloatField;
323
    ClientDataSetFeedsCysd: TFloatField;
324
    ClientDataSetFeedsMetCysd: TFloatField;
325
    ClientDataSetFeedsTrpd: TFloatField;
326
    ClientDataSetFeedsIled: TFloatField;
327
    ClientDataSetFeedsVald: TFloatField;
328
    ClientDataSetFeedsLeud: TFloatField;
329
    ClientDataSetFeedsPhed: TFloatField;
330
    ClientDataSetFeedsTyrd: TFloatField;
331
    ClientDataSetFeedsPheTyrd: TFloatField;
332
    ClientDataSetFeedsHisd: TFloatField;
333
    ClientDataSetFeedsArgd: TFloatField;
334
    ClientDataSetFeedsAlad: TFloatField;
335
    ClientDataSetFeedsAspd: TFloatField;
336
    ClientDataSetFeedsGlud: TFloatField;
337
    ClientDataSetFeedsGlyd: TFloatField;
338
    ClientDataSetFeedsSerd: TFloatField;
339
    ClientDataSetFeedsProd: TFloatField;
340
    ClientDataSetFeedsLysd_ENc: TFloatField;
341
    ClientDataSetFeedsLysd_ENt: TFloatField;
342
    ClientDataSetFeedsThrd_Lysd: TFloatField;
343
    ClientDataSetFeedsMetd_Lysd: TFloatField;
344
    ClientDataSetFeedsCysd_Lysd: TFloatField;
345
    ClientDataSetFeedsMetCysd_Lysd: TFloatField;
346
    ClientDataSetFeedsTrpd_Lysd: TFloatField;
347
    ClientDataSetFeedsIled_Lysd: TFloatField;
348
    ClientDataSetFeedsVald_Lysd: TFloatField;
349
    ClientDataSetFeedsLeud_Lysd: TFloatField;
350
    ClientDataSetFeedsPhed_Lysd: TFloatField;
351
    ClientDataSetFeedsTyrd_Lysd: TFloatField;
352
    ClientDataSetFeedsPheTyrd_Lysd: TFloatField;
353
    ClientDataSetFeedsHisd_Lysd: TFloatField;
354
    ClientDataSetFeedsArgd_Lysd: TFloatField;
355
    ClientDataSetFeedsAlad_Lysd: TFloatField;
356
    ClientDataSetFeedsAspd_Lysd: TFloatField;
357
    ClientDataSetFeedsGlud_Lysd: TFloatField;
358
    ClientDataSetFeedsGlyd_Lysd: TFloatField;
359
    ClientDataSetFeedsSerd_Lysd: TFloatField;
360
    ClientDataSetFeedsProd_Lysd: TFloatField;
361
    ClientDataSetFeedsCa: TFloatField;
362
    ClientDataSetFeedsP: TFloatField;
363
    ClientDataSetFeedsPd: TFloatField;
364
    ClientDataSetFeedsCa_Pd: TFloatField;
365
    ClientDataSetFeedsPd_ENc: TFloatField;
366
    ClientDataSetFeedsPd_ENt: TFloatField;
367
    ClientDataSetFeedsPhytaseId: TIntegerField;
368
    ClientDataSetFeedsPhytaseType: TFloatField;
369
    ClientDataSetFeedsPhytaseConcentration: TFloatField;
370
    ClientDataSetFeedsPhytaseIncorporation: TFloatField;
371
    ClientDataSetFeedsPhytaseLevel: TFloatField;
372
    ClientDataSetFeedsLevelSum: TFloatField;
373
    ClientDataSetFeedsTotal: TFloatField;
374
    ClientDataSetFeedsRemain: TFloatField;
375
    ClientDataSetFeedsNa: TFloatField;
376
    ClientDataSetFeedsK: TFloatField;
377
    ClientDataSetFeedsCl: TFloatField;
378
    ClientDataSetFeedsBE: TFloatField;
379
    DataSourceFeeds: TDataSource;
380
    procedure DataModuleCreate(Sender: TObject);
381
    procedure DataModuleDestroy(Sender: TObject);
382
    procedure ClientDataSetIngredientsFilterRecord(DataSet: TDataSet; var Accept: Boolean);
383
    procedure ClientDataSetFeedsCalcFields(DataSet: TDataSet);
384
    procedure AggregateLevelSumUpdate(Agg: TAggregate);
385
  private
386
    { D?clarations priv?es }
387
  public
388
    { D?clarations publiques }
389
    DBUser: TSQLiteDatabase;
390
    TableIngredients: TSQLiteTable;
391
    TableFeeds: TSQLiteTable;
392
    TableComposition: TSQLiteTable;
393
    RapMS, RapMAT: Double;
394
    ClassList, UserList, FeedList: TStrings;
395
    FilterOnClass, FilterOnDatabase, FilterOnName: Boolean;
396
    FilteredClass, FilteredDatabase: Integer;
397
    FilteredName: String;
398
    procedure CalcInraAfz;
399
    procedure CalcOriginal;
400
    procedure CalcCopy;
401
    procedure CalcFeed;
402
    function CalcBilanElectrolytique(Na, K, Cl: Double): Double;
403
    function InputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
404
    function InputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
405
    function InputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
406
    function InputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
407
    function InputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
408
    function OutputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
409
    function OutputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
410
    function OutputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
411
    function OutputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
412
    function OutputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
413
    function StrTrunc(S: String; Max: Integer): String;
414
  end;
415

    
416
var
417
  DataModuleDeclaration: TDataModuleDeclaration;
418
  MajorVersion, MinorVersion, ReleaseVersion, BuildVersion: Integer ;
419

    
420
implementation
421

    
422
{$R *.dfm}
423

    
424
uses
425
  SHFolder, StrUtils, UnitOptions;
426

    
427
procedure TDataModuleDeclaration.AggregateLevelSumUpdate(Agg: TAggregate);
428
begin
429
  if not ClientDataSetFeeds.Eof
430
  then
431
  begin
432
    ClientDataSetFeeds.Edit;
433
    if VarIsEmpty(Agg.Value) or VarIsNull(Agg.Value)
434
    then
435
      ClientDataSetFeedsLevelSum.Clear
436
    else
437
      ClientDataSetFeedsLevelSum.AsFloat := Agg.Value;
438
    ClientDataSetFeeds.Post;
439
  end;
440
end;
441

    
442
procedure TDataModuleDeclaration.ClientDataSetFeedsCalcFields(DataSet: TDataSet);
443
begin
444
  if ClientDataSetFeedsPhytaseIncorporation.IsNull or ClientDataSetFeedsPhytaseConcentration.IsNull
445
  or (ClientDataSetFeedsPhytaseConcentration.Value = 0)
446
  then
447
    ClientDataSetFeedsPhytaseLevel.Clear
448
  else
449
    ClientDataSetFeedsPhytaseLevel.Value := OutputIncorporation(ClientDataSetFeedsPhytaseIncorporation.Value / ClientDataSetFeedsPhytaseConcentration.Value / 1000, FormOptions.Incorporation);
450
  ClientDataSetFeedsTotal.Value := ClientDataSetFeedsLevelSum.Value + ClientDataSetFeedsPhytaseLevel.Value;
451
  ClientDataSetFeedsRemain.Value := OutputIncorporation(1, FormOptions.Incorporation) - ClientDataSetFeedsTotal.Value;
452
end;
453

    
454
procedure TDataModuleDeclaration.ClientDataSetIngredientsFilterRecord(DataSet: TDataSet; var Accept: Boolean);
455
begin
456
  Accept := True;
457
  if FilterOnClass and (FilteredClass > 0)
458
  then
459
    Accept := Accept and (DataSet.FieldByName('Class').AsInteger = FilteredClass);
460
  if FilterOnDatabase
461
  then
462
    case FilteredDatabase of
463
      1: // User database
464
        Accept := Accept and DataSet.FieldByName('User').AsBoolean;
465
      2: // Reference tables
466
        Accept := Accept and not DataSet.FieldByName('User').AsBoolean;
467
    end;
468
  if FilterOnName and (FilteredName <> '')
469
  then
470
    Accept := Accept and (Pos(FilteredName, DataSet.FieldByName('Name').AsWideString) > 0);
471
end;
472

    
473
procedure TDataModuleDeclaration.DataModuleCreate(Sender: TObject);
474
var
475
  i: Integer;
476
  ExeDir, DataDir, DataFile: String;
477
  Cryptage: TLbBlowfish;
478
  FluxClair, FluxCrypte: TMemoryStream;
479
  DocumentsPath: array[0..MAX_PATH] of Char;
480
begin
481
  // Classes
482
  ClassList := TStringList.Create;
483
  ClassList.Add('Cereals');
484
  ClassList.Add('Wheat by-products');
485
  ClassList.Add('Maize by-products');
486
  ClassList.Add('Other cereal by-products');
487
  ClassList.Add('Rice by-products');
488
  ClassList.Add('Legume and oil seeds');
489
  ClassList.Add('Oil seed meals');
490
  ClassList.Add('Starch, roots and tubers');
491
  ClassList.Add('Fruits and vegetables by-products');
492
  ClassList.Add('Molasses and vinasses');
493
  ClassList.Add('Other plant products');
494
  ClassList.Add('Dehydrated forages');
495
  ClassList.Add('Dairy products');
496
  ClassList.Add('Fish meals and solubles');
497
  ClassList.Add('Other animal by-products');
498
  ClassList.Add('Fats and oils');
499
  ClassList.Add('Amino acids');
500
  ClassList.Add('Mineral sources');
501
  ClassList.Add('Not referenced');
502
  ClientDataSetClasses.CreateDataSet;
503
  for i := 0 to ClassList.Count - 1 do
504
    ClientDataSetClasses.AppendRecord([i + 1, dgettext('InraAfz', ClassList[i])]);
505
  // Phytase
506
  ClientDataSetPhytase.CreateDataSet;
507
  ClientDataSetPhytase.AppendRecord([1, 0.60, 0.67]);
508
  ClientDataSetPhytase.AppendRecord([2, 0.65, 0.76]);
509
  ClientDataSetPhytase.AppendRecord([3, 0.70, 0.87]);
510
  ClientDataSetPhytase.AppendRecord([4, 0.75, 1.00]);
511
  ClientDataSetPhytase.AppendRecord([5, 0.80, 1.15]);
512
  ClientDataSetPhytase.AppendRecord([6, 0.85, 1.34]);
513
  ClientDataSetPhytase.AppendRecord([7, 0.90, 1.60]);
514
  ClientDataSetPhytase.AppendRecord([8, 0.95, 1.98]);
515
  // Tables de r?f?rence
516
  ExeDir := ExtractFilePath(Application.ExeName);
517
  DataFile := ExeDir + 'EvaPig2020.dat';
518
  if not FileExists(DataFile)
519
  then // Erreur
520
  begin
521
    MessageDlg(_('Reference tables of composition and nutritional values of feed materials for pigs') + sLineBreak
522
      + Format(_('%s: file not found'), [DataFile]), mtError, [mbOK], 0);
523
    Application.Terminate;
524
    Exit;
525
  end;
526
  ClientDataSetInraAfz.CreateDataSet;
527
  Cryptage := TlbBlowfish.Create(nil);
528
  Cryptage.GenerateKey('Tables of Composition and Nutritional Value of Feed Materials');
529
  FluxCrypte := TMemoryStream.Create;
530
  FluxClair := TMemoryStream.Create;
531
  try
532
    FluxCrypte.LoadFromFile(DataFile);
533
    FluxCrypte.Position := 0;
534
    Cryptage.DecryptStream(FluxCrypte, FluxClair);
535
    FluxClair.Position := 0;
536
    try
537
      ClientDataSetInraAfz.LoadFromStream(FluxClair);
538
    except
539
      MessageDlg(_('Reference tables of composition and nutritional values of feed materials for pigs') + sLineBreak
540
        + _('Invalid data format'), mtError, [mbOK], 0);
541
      Application.Terminate;
542
      Exit;
543
    end;
544
  finally
545
    FluxCrypte.Free;
546
    FluxClair.Free;
547
    Cryptage.Free;
548
  end;
549
  // Base User.sqb
550
  SHGetFolderPath(0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, DocumentsPath);
551
  DataDir := IncludeTrailingPathDelimiter(IncludeTrailingPathDelimiter(DocumentsPath) + Application.Title);
552
  ForceDirectories(DataDir);
553
  if not FileExists(ExeDir + 'sqlite3.dll')
554
  then // Erreur
555
  begin
556
    MessageDlg(_('SQLite') + sLineBreak
557
      + Format(_('%s: driver missing'), [ExeDir + 'sqlite3.dll']), mtError, [mbOK], 0);
558
    Application.Terminate;
559
    Exit;
560
  end;
561
  DBUser := TSQLiteDatabase.Create(DataDir + 'User.sqb');
562
  if not DBUser.TableExists('Ingredients')
563
  then // Cr?ation de la table Ingredients
564
  begin
565
    DBUser.ExecSQL('CREATE TABLE Ingredients ('
566
      + 'Id INTEGER PRIMARY KEY, '
567
      + 'Name TEXT, '
568
      + 'Definition TEXT, '
569
      + 'Class INTEGER, '
570
      + 'Model INTEGER, '
571
      + 'MS REAL, '
572
      + 'MM REAL, '
573
      + 'MAT REAL, '
574
      + 'MG REAL, '
575
      + 'CB REAL, '
576
      + 'NDF REAL, '
577
      + 'ADF REAL, '
578
      + 'ADL REAL, '
579
      + 'Amidon REAL, '
580
      + 'Sucres REAL, '
581
      + 'EB REAL, '
582
      + 'Bonus REAL, '
583
      + 'Lys REAL, '
584
      + 'Thr REAL, '
585
      + 'Met REAL, '
586
      + 'Cys REAL, '
587
      + 'MetCys REAL, '
588
      + 'Trp REAL, '
589
      + 'Ile REAL, '
590
      + 'Val REAL, '
591
      + 'Leu REAL, '
592
      + 'Phe REAL, '
593
      + 'Tyr REAL, '
594
      + 'PheTyr REAL, '
595
      + 'His REAL, '
596
      + 'Arg REAL, '
597
      + 'Ala REAL, '
598
      + 'Asp REAL, '
599
      + 'Glu REAL, '
600
      + 'Gly REAL, '
601
      + 'Ser REAL, '
602
      + 'Pro REAL, '
603
      + 'dLys REAL, '
604
      + 'dThr REAL, '
605
      + 'dMet REAL, '
606
      + 'dCys REAL, '
607
      + 'dMetCys REAL, '
608
      + 'dTrp REAL, '
609
      + 'dIle REAL, '
610
      + 'dVal REAL, '
611
      + 'dLeu REAL, '
612
      + 'dPhe REAL, '
613
      + 'dTyr REAL, '
614
      + 'dPheTyr REAL, '
615
      + 'dHis REAL, '
616
      + 'dArg REAL, '
617
      + 'dAla REAL, '
618
      + 'dAsp REAL, '
619
      + 'dGlu REAL, '
620
      + 'dGly REAL, '
621
      + 'dSer REAL, '
622
      + 'dPro REAL, '
623
      + 'Ca REAL, '
624
      + 'P REAL, '
625
      + 'Na REAL, '
626
      + 'K REAL, '
627
      + 'Cl REAL, '
628
      + 'dP REAL, '
629
      + 'dPphy REAL)');
630
    DBUser.ExecSQL('CREATE INDEX IdxClasses ON Ingredients (Class)');
631
    DBUser.ExecSQL('CREATE INDEX IdxModels ON Ingredients (Model)');
632
  end;
633
  if not DBUser.TableExists('Feeds')
634
  then // Cr?ation de la table Feeds
635
    DBUser.ExecSQL('CREATE TABLE Feeds ('
636
      + 'Id INTEGER PRIMARY KEY, '
637
      + 'Name TEXT, '
638
      + 'Description TEXT, '
639
      + 'Presentation INTEGER, '
640
      + 'BonusC REAL, '
641
      + 'BonusT REAL, '
642
      + 'Phytase INTEGER, '
643
      + 'Concentration REAL, '
644
      + 'Incorporation REAL)');
645
  if not DBUser.TableExists('Composition')
646
  then // Cr?ation de la table Composition
647
  begin
648
    DBUser.ExecSQL('CREATE TABLE Composition ('
649
      + 'Feed INTEGER, '
650
      + 'Ingredient INTEGER, '
651
      + 'User BOOLEAN, '
652
      + 'Rank INTEGER, '
653
      + 'MS REAL, '
654
      + 'Level REAL)');
655
    DBUser.ExecSQL('CREATE INDEX IdxFeeds ON Composition (Feed)');
656
    DBUser.ExecSQL('CREATE INDEX IdxIngredients ON Composition (Ingredient)');
657
  end;
658
  Application.ProcessMessages;
659
  // Liste des mati?res premi?res utilisateur
660
  UserList := TStringList.Create;
661
  TableIngredients := DBUser.GetTable('SELECT Name FROM Ingredients');
662
  with TableIngredients do
663
    try
664
      while not Eof do
665
      begin
666
        UserList.Add(FieldAsString(FieldIndex['Name']));
667
        Next;
668
      end;
669
    finally
670
      Free;
671
    end;
672
  // Liste des r?gimes
673
  FeedList := TStringList.Create;
674
  TableFeeds := DBUser.GetTable('SELECT Name FROM Feeds');
675
  with TableFeeds do
676
    try
677
      while not Eof do
678
      begin
679
        FeedList.Add(FieldAsString(FieldIndex['Name']));
680
        Next;
681
      end;
682
    finally
683
      Free;
684
    end;
685
end;
686

    
687
procedure TDataModuleDeclaration.DataModuleDestroy(Sender: TObject);
688
begin
689
  ClientDataSetClasses.Close;
690
  ClientDataSetPhytase.Close;
691
  ClientDataSetInraAfz.Close;
692
  ClassList.Free;
693
  UserList.Free;
694
  FeedList.Free;
695
  Application.ProcessMessages;
696
  DBUser.ExecSQL('VACUUM'); // Compacter la base User.sqb
697
  DBUser.Free;
698
  Application.ProcessMessages;
699
end;
700

    
701
procedure TDataModuleDeclaration.CalcInraAfz;
702
// Renseigner l'enregistrement courant de ClientDataSetIngredients
703
// ? partir de l'enregistrement courant de ClientDataSetInraAfz
704
// en tenant compte des unit?s configur?es
705
begin
706
  // Analyse proximale
707
  RapMS := ClientDataSetInraAfzMS.Value;
708
  ClientDataSetIngredientsMS.Value := OutputProximal(RapMS, 1, 1, FormOptions.Proximal);
709
  ClientDataSetIngredientsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
710
  if ClientDataSetInraAfzMM.IsNull
711
  then
712
    ClientDataSetIngredientsMM.Clear
713
  else
714
    ClientDataSetIngredientsMM.Value := OutputProximal(ClientDataSetInraAfzMM.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
715
  if ClientDataSetInraAfzMAT.IsNull
716
  then
717
    ClientDataSetIngredientsMAT.Clear
718
  else
719
  begin
720
    RapMAT := ClientDataSetInraAfzMAT.Value;
721
    ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
722
  end;
723
  if ClientDataSetInraAfzMG.IsNull
724
  then
725
    ClientDataSetIngredientsMG.Clear
726
  else
727
    ClientDataSetIngredientsMG.Value := OutputProximal(ClientDataSetInraAfzMG.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
728
  if ClientDataSetInraAfzCB.IsNull
729
  then
730
    ClientDataSetIngredientsCB.Clear
731
  else
732
    ClientDataSetIngredientsCB.Value := OutputProximal(ClientDataSetInraAfzCB.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
733
  if ClientDataSetInraAfzNDF.IsNull
734
  then
735
    ClientDataSetIngredientsNDF.Clear
736
  else
737
    ClientDataSetIngredientsNDF.Value := OutputProximal(ClientDataSetInraAfzNDF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
738
  if ClientDataSetInraAfzADF.IsNull
739
  then
740
    ClientDataSetIngredientsADF.Clear
741
  else
742
    ClientDataSetIngredientsADF.Value := OutputProximal(ClientDataSetInraAfzADF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
743
  if ClientDataSetInraAfzADL.IsNull
744
  then
745
    ClientDataSetIngredientsADL.Clear
746
  else
747
    ClientDataSetIngredientsADL.Value := OutputProximal(ClientDataSetInraAfzADL.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
748
  if ClientDataSetInraAfzAmidon.IsNull
749
  then
750
    ClientDataSetIngredientsAmidon.Clear
751
  else
752
    ClientDataSetIngredientsAmidon.Value := OutputProximal(ClientDataSetInraAfzAmidon.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
753
  if ClientDataSetInraAfzSucres.IsNull
754
  then
755
    ClientDataSetIngredientsSucres.Clear
756
  else
757
    ClientDataSetIngredientsSucres.Value := OutputProximal(ClientDataSetInraAfzSucres.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
758
  // Energie
759
  ClientDataSetIngredientsEB.Value := OutputEnergy(ClientDataSetInraAfzEB.Value, RapMS, FormOptions.Expression, FormOptions.Energy);
760
  ClientDataSetIngredientsBonus.Value := 0;
761
  ClientDataSetIngredientsdEc.Value := ClientDataSetInraAfzdEc.Value * 100;
762
  ClientDataSetIngredientsEDc.Value := ClientDataSetIngredientsEB.Value * ClientDataSetIngredientsdEc.Value / 100;
763
  ClientDataSetIngredientsEMc_EDc.Value := ClientDataSetInraAfzEMc_EDc.Value * 100;
764
  ClientDataSetIngredientsEMc.Value := ClientDataSetIngredientsEDc.Value * ClientDataSetIngredientsEMc_EDc.Value / 100;
765
  ClientDataSetIngredientsENc_EMc.Value := ClientDataSetInraAfzENc_EMc.Value * 100;
766
  ClientDataSetIngredientsENc.Value := ClientDataSetIngredientsEMc.Value * ClientDataSetIngredientsENc_EMc.Value / 100;
767
  ClientDataSetIngredientsEDt_EDc.Value := ClientDataSetInraAfzEDt_EDc.Value * 100;
768
  ClientDataSetIngredientsEDt.Value := ClientDataSetIngredientsEDc.Value * ClientDataSetIngredientsEDt_EDc.Value / 100;
769
  ClientDataSetIngredientsEMt_EDt.Value := ClientDataSetInraAfzEMt_EDt.Value * 100;
770
  ClientDataSetIngredientsEMt.Value := ClientDataSetIngredientsEDt.Value * ClientDataSetIngredientsEMt_EDt.Value / 100;
771
  ClientDataSetIngredientsENt_EMt.Value := ClientDataSetInraAfzENt_EMt.Value * 100;
772
  ClientDataSetIngredientsENt.Value := ClientDataSetIngredientsEMt.Value * ClientDataSetIngredientsENt_EMt.Value / 100;
773
  if ClientDataSetIngredientsEB.Value = 0
774
  then
775
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsdEc.Value
776
  else
777
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsEDt.Value / ClientDataSetIngredientsEB.Value * 100;
778
  if ClientDataSetIngredientsEMc.Value = 0
779
  then
780
    ClientDataSetIngredientsEMt_EMc.Value := 100
781
  else
782
    ClientDataSetIngredientsEMt_EMc.Value := ClientDataSetIngredientsEMt.Value / ClientDataSetIngredientsEMc.Value * 100;
783
  if ClientDataSetIngredientsENc.Value = 0
784
  then
785
    ClientDataSetIngredientsENt_ENc.Value := 100
786
  else
787
    ClientDataSetIngredientsENt_ENc.Value := ClientDataSetIngredientsENt.Value / ClientDataSetIngredientsENc.Value * 100;
788
  // Digestibilit? f?cale de l'azote
789
  if ClientDataSetInraAfzdNc.IsNull
790
  then
791
    ClientDataSetIngredientsdNc.Clear
792
  else
793
    ClientDataSetIngredientsdNc.Value := ClientDataSetInraAfzdNc.Value * 100;
794
  if ClientDataSetInraAfzdNt.IsNull
795
  then
796
    ClientDataSetIngredientsdNt.Clear
797
  else
798
    ClientDataSetIngredientsdNt.Value := ClientDataSetInraAfzdNt.Value * 100;
799
  // Acides amin?s
800
  if RapMAT = 0
801
  then // En l'absence de MAT, il n'y a pas d'acides amin?s
802
  begin
803
    // Teneurs
804
    ClientDataSetIngredientsLys.Clear;
805
    ClientDataSetIngredientsThr.Clear;
806
    ClientDataSetIngredientsMet.Clear;
807
    ClientDataSetIngredientsCys.Clear;
808
    ClientDataSetIngredientsMetCys.Clear;
809
    ClientDataSetIngredientsTrp.Clear;
810
    ClientDataSetIngredientsIle.Clear;
811
    ClientDataSetIngredientsVal.Clear;
812
    ClientDataSetIngredientsLeu.Clear;
813
    ClientDataSetIngredientsPhe.Clear;
814
    ClientDataSetIngredientsTyr.Clear;
815
    ClientDataSetIngredientsPheTyr.Clear;
816
    ClientDataSetIngredientsHis.Clear;
817
    ClientDataSetIngredientsArg.Clear;
818
    ClientDataSetIngredientsAla.Clear;
819
    ClientDataSetIngredientsAsp.Clear;
820
    ClientDataSetIngredientsGlu.Clear;
821
    ClientDataSetIngredientsGly.Clear;
822
    ClientDataSetIngredientsSer.Clear;
823
    ClientDataSetIngredientsPro.Clear;
824
    // % MAT
825
    ClientDataSetIngredientsLys_MAT.Clear;
826
    ClientDataSetIngredientsThr_MAT.Clear;
827
    ClientDataSetIngredientsMet_MAT.Clear;
828
    ClientDataSetIngredientsCys_MAT.Clear;
829
    ClientDataSetIngredientsMetCys_MAT.Clear;
830
    ClientDataSetIngredientsTrp_MAT.Clear;
831
    ClientDataSetIngredientsIle_MAT.Clear;
832
    ClientDataSetIngredientsVal_MAT.Clear;
833
    ClientDataSetIngredientsLeu_MAT.Clear;
834
    ClientDataSetIngredientsPhe_MAT.Clear;
835
    ClientDataSetIngredientsTyr_MAT.Clear;
836
    ClientDataSetIngredientsPheTyr_MAT.Clear;
837
    ClientDataSetIngredientsHis_MAT.Clear;
838
    ClientDataSetIngredientsArg_MAT.Clear;
839
    ClientDataSetIngredientsAla_MAT.Clear;
840
    ClientDataSetIngredientsAsp_MAT.Clear;
841
    ClientDataSetIngredientsGlu_MAT.Clear;
842
    ClientDataSetIngredientsGly_MAT.Clear;
843
    ClientDataSetIngredientsSer_MAT.Clear;
844
    ClientDataSetIngredientsPro_MAT.Clear;
845
    // Digestibilit?s
846
    ClientDataSetIngredientsdLys.Clear;
847
    ClientDataSetIngredientsdThr.Clear;
848
    ClientDataSetIngredientsdMet.Clear;
849
    ClientDataSetIngredientsdCys.Clear;
850
    ClientDataSetIngredientsdMetCys.Clear;
851
    ClientDataSetIngredientsdTrp.Clear;
852
    ClientDataSetIngredientsdIle.Clear;
853
    ClientDataSetIngredientsdVal.Clear;
854
    ClientDataSetIngredientsdLeu.Clear;
855
    ClientDataSetIngredientsdPhe.Clear;
856
    ClientDataSetIngredientsdTyr.Clear;
857
    ClientDataSetIngredientsdPheTyr.Clear;
858
    ClientDataSetIngredientsdHis.Clear;
859
    ClientDataSetIngredientsdArg.Clear;
860
    ClientDataSetIngredientsdAla.Clear;
861
    ClientDataSetIngredientsdAsp.Clear;
862
    ClientDataSetIngredientsdGlu.Clear;
863
    ClientDataSetIngredientsdGly.Clear;
864
    ClientDataSetIngredientsdSer.Clear;
865
    ClientDataSetIngredientsdPro.Clear;
866
    // Teneurs digestibles
867
    ClientDataSetIngredientsLysd.Clear;
868
    ClientDataSetIngredientsThrd.Clear;
869
    ClientDataSetIngredientsMetd.Clear;
870
    ClientDataSetIngredientsCysd.Clear;
871
    ClientDataSetIngredientsMetCysd.Clear;
872
    ClientDataSetIngredientsTrpd.Clear;
873
    ClientDataSetIngredientsIled.Clear;
874
    ClientDataSetIngredientsVald.Clear;
875
    ClientDataSetIngredientsLeud.Clear;
876
    ClientDataSetIngredientsPhed.Clear;
877
    ClientDataSetIngredientsTyrd.Clear;
878
    ClientDataSetIngredientsPheTyrd.Clear;
879
    ClientDataSetIngredientsHisd.Clear;
880
    ClientDataSetIngredientsArgd.Clear;
881
    ClientDataSetIngredientsAlad.Clear;
882
    ClientDataSetIngredientsAspd.Clear;
883
    ClientDataSetIngredientsGlud.Clear;
884
    ClientDataSetIngredientsGlyd.Clear;
885
    ClientDataSetIngredientsSerd.Clear;
886
    ClientDataSetIngredientsProd.Clear;
887
  end
888
  else
889
  begin
890
    // Lys
891
    if ClientDataSetInraAfzLys.IsNull
892
    then
893
    begin
894
      ClientDataSetIngredientsLys.Clear;
895
      ClientDataSetIngredientsLys_MAT.Clear;
896
      ClientDataSetIngredientsdLys.Clear;
897
      ClientDataSetIngredientsLysd.Clear;
898
    end
899
    else
900
    begin
901
      ClientDataSetIngredientsLys.Value := OutputAA(ClientDataSetInraAfzLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
902
      ClientDataSetIngredientsLys_MAT.Value := InputAA(ClientDataSetIngredientsLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
903
      if ClientDataSetInraAfzdLys.IsNull
904
      then
905
        ClientDataSetIngredientsdLys.Value := dLys * 100
906
      else
907
        ClientDataSetIngredientsdLys.Value := ClientDataSetInraAfzdLys.Value * 100;
908
      ClientDataSetIngredientsLysd.Value := ClientDataSetIngredientsdLys.Value / 100 * ClientDataSetIngredientsLys.Value;
909
    end;
910
    // Thr
911
    if ClientDataSetInraAfzThr.IsNull
912
    then
913
    begin
914
      ClientDataSetIngredientsThr.Clear;
915
      ClientDataSetIngredientsThr_MAT.Clear;
916
      ClientDataSetIngredientsdThr.Clear;
917
      ClientDataSetIngredientsThrd.Clear;
918
    end
919
    else
920
    begin
921
      ClientDataSetIngredientsThr.Value := OutputAA(ClientDataSetInraAfzThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
922
      ClientDataSetIngredientsThr_MAT.Value := InputAA(ClientDataSetIngredientsThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
923
      if ClientDataSetInraAfzdThr.IsNull
924
      then
925
        ClientDataSetIngredientsdThr.Value := dThr * 100
926
      else
927
        ClientDataSetIngredientsdThr.Value := ClientDataSetInraAfzdThr.Value * 100;
928
      ClientDataSetIngredientsThrd.Value := ClientDataSetIngredientsdThr.Value / 100 * ClientDataSetIngredientsThr.Value;
929
    end;
930
    // Met
931
    if ClientDataSetInraAfzMet.IsNull
932
    then
933
    begin
934
      ClientDataSetIngredientsMet.Clear;
935
      ClientDataSetIngredientsMet_MAT.Clear;
936
      ClientDataSetIngredientsdMet.Clear;
937
      ClientDataSetIngredientsMetd.Clear;
938
    end
939
    else
940
    begin
941
      ClientDataSetIngredientsMet.Value := OutputAA(ClientDataSetInraAfzMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
942
      ClientDataSetIngredientsMet_MAT.Value := InputAA(ClientDataSetIngredientsMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
943
      if ClientDataSetInraAfzdMet.IsNull
944
      then
945
        ClientDataSetIngredientsdMet.Value := dMet * 100
946
      else
947
        ClientDataSetIngredientsdMet.Value := ClientDataSetInraAfzdMet.Value * 100;
948
      ClientDataSetIngredientsMetd.Value := ClientDataSetIngredientsdMet.Value / 100 * ClientDataSetIngredientsMet.Value;
949
    end;
950
    // Cys
951
    if ClientDataSetInraAfzCys.IsNull
952
    then
953
    begin
954
      ClientDataSetIngredientsCys.Clear;
955
      ClientDataSetIngredientsCys_MAT.Clear;
956
      ClientDataSetIngredientsdCys.Clear;
957
      ClientDataSetIngredientsCysd.Clear;
958
    end
959
    else
960
    begin
961
      ClientDataSetIngredientsCys.Value := OutputAA(ClientDataSetInraAfzCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
962
      ClientDataSetIngredientsCys_MAT.Value := InputAA(ClientDataSetIngredientsCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
963
      if ClientDataSetInraAfzdCys.IsNull
964
      then
965
        ClientDataSetIngredientsdCys.Value := dCys * 100
966
      else
967
        ClientDataSetIngredientsdCys.Value := ClientDataSetInraAfzdCys.Value * 100;
968
      ClientDataSetIngredientsCysd.Value := ClientDataSetIngredientsdCys.Value / 100 * ClientDataSetIngredientsCys.Value;
969
    end;
970
    // Met + Cys
971
    if ClientDataSetInraAfzMetCys.IsNull
972
    then
973
    begin
974
      ClientDataSetIngredientsMetCys.Clear;
975
      ClientDataSetIngredientsMetCys_MAT.Clear;
976
      ClientDataSetIngredientsdMetCys.Clear;
977
      ClientDataSetIngredientsMetCysd.Clear;
978
    end
979
    else
980
    begin
981
      ClientDataSetIngredientsMetCys.Value := OutputAA(ClientDataSetInraAfzMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
982
      ClientDataSetIngredientsMetCys_MAT.Value := InputAA(ClientDataSetIngredientsMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
983
      if ClientDataSetInraAfzdMetCys.IsNull
984
      then
985
        ClientDataSetIngredientsdMetCys.Value := dMetCys * 100
986
      else
987
        ClientDataSetIngredientsdMetCys.Value := ClientDataSetInraAfzdMetCys.Value * 100;
988
      ClientDataSetIngredientsMetCysd.Value := ClientDataSetIngredientsdMetCys.Value / 100 * ClientDataSetIngredientsMetCys.Value;
989
    end;
990
    // Trp
991
    if ClientDataSetInraAfzTrp.IsNull
992
    then
993
    begin
994
      ClientDataSetIngredientsTrp.Clear;
995
      ClientDataSetIngredientsTrp_MAT.Clear;
996
      ClientDataSetIngredientsdTrp.Clear;
997
      ClientDataSetIngredientsTrpd.Clear;
998
    end
999
    else
1000
    begin
1001
      ClientDataSetIngredientsTrp.Value := OutputAA(ClientDataSetInraAfzTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1002
      ClientDataSetIngredientsTrp_MAT.Value := InputAA(ClientDataSetIngredientsTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1003
      if ClientDataSetInraAfzdTrp.IsNull
1004
      then
1005
        ClientDataSetIngredientsdTrp.Value := dTrp * 100
1006
      else
1007
        ClientDataSetIngredientsdTrp.Value := ClientDataSetInraAfzdTrp.Value * 100;
1008
      ClientDataSetIngredientsTrpd.Value := ClientDataSetIngredientsdTrp.Value / 100 * ClientDataSetIngredientsTrp.Value;
1009
    end;
1010
    // Ile
1011
    if ClientDataSetInraAfzIle.IsNull
1012
    then
1013
    begin
1014
      ClientDataSetIngredientsIle.Clear;
1015
      ClientDataSetIngredientsIle_MAT.Clear;
1016
      ClientDataSetIngredientsdIle.Clear;
1017
      ClientDataSetIngredientsIled.Clear;
1018
    end
1019
    else
1020
    begin
1021
      ClientDataSetIngredientsIle.Value := OutputAA(ClientDataSetInraAfzIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1022
      ClientDataSetIngredientsIle_MAT.Value := InputAA(ClientDataSetIngredientsIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1023
      if ClientDataSetInraAfzdIle.IsNull
1024
      then
1025
        ClientDataSetIngredientsdIle.Value := dIle * 100
1026
      else
1027
        ClientDataSetIngredientsdIle.Value := ClientDataSetInraAfzdIle.Value * 100;
1028
      ClientDataSetIngredientsIled.Value := ClientDataSetIngredientsdIle.Value / 100 * ClientDataSetIngredientsIle.Value;
1029
    end;
1030
    // Val
1031
    if ClientDataSetInraAfzVal.IsNull
1032
    then
1033
    begin
1034
      ClientDataSetIngredientsVal.Clear;
1035
      ClientDataSetIngredientsVal_MAT.Clear;
1036
      ClientDataSetIngredientsdVal.Clear;
1037
      ClientDataSetIngredientsVald.Clear;
1038
    end
1039
    else
1040
    begin
1041
      ClientDataSetIngredientsVal.Value := OutputAA(ClientDataSetInraAfzVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1042
      ClientDataSetIngredientsVal_MAT.Value := InputAA(ClientDataSetIngredientsVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1043
      if ClientDataSetInraAfzdVal.IsNull
1044
      then
1045
        ClientDataSetIngredientsdVal.Value := dVal * 100
1046
      else
1047
        ClientDataSetIngredientsdVal.Value := ClientDataSetInraAfzdVal.Value * 100;
1048
      ClientDataSetIngredientsVald.Value := ClientDataSetIngredientsdVal.Value / 100 * ClientDataSetIngredientsVal.Value;
1049
    end;
1050
    // Leu
1051
    if ClientDataSetInraAfzLeu.IsNull
1052
    then
1053
    begin
1054
      ClientDataSetIngredientsLeu.Clear;
1055
      ClientDataSetIngredientsLeu_MAT.Clear;
1056
      ClientDataSetIngredientsdLeu.Clear;
1057
      ClientDataSetIngredientsLeud.Clear;
1058
    end
1059
    else
1060
    begin
1061
      ClientDataSetIngredientsLeu.Value := OutputAA(ClientDataSetInraAfzLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1062
      ClientDataSetIngredientsLeu_MAT.Value := InputAA(ClientDataSetIngredientsLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1063
      if ClientDataSetInraAfzdLeu.IsNull
1064
      then
1065
        ClientDataSetIngredientsdLeu.Value := dLeu * 100
1066
      else
1067
        ClientDataSetIngredientsdLeu.Value := ClientDataSetInraAfzdLeu.Value * 100;
1068
      ClientDataSetIngredientsLeud.Value := ClientDataSetIngredientsdLeu.Value / 100 * ClientDataSetIngredientsLeu.Value;
1069
    end;
1070
    // Phe
1071
    if ClientDataSetInraAfzPhe.IsNull
1072
    then
1073
    begin
1074
      ClientDataSetIngredientsPhe.Clear;
1075
      ClientDataSetIngredientsPhe_MAT.Clear;
1076
      ClientDataSetIngredientsdPhe.Clear;
1077
      ClientDataSetIngredientsPhed.Clear;
1078
    end
1079
    else
1080
    begin
1081
      ClientDataSetIngredientsPhe.Value := OutputAA(ClientDataSetInraAfzPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1082
      ClientDataSetIngredientsPhe_MAT.Value := InputAA(ClientDataSetIngredientsPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1083
      if ClientDataSetInraAfzdPhe.IsNull
1084
      then
1085
        ClientDataSetIngredientsdPhe.Value := dPhe * 100
1086
      else
1087
        ClientDataSetIngredientsdPhe.Value := ClientDataSetInraAfzdPhe.Value * 100;
1088
      ClientDataSetIngredientsPhed.Value := ClientDataSetIngredientsdPhe.Value / 100 * ClientDataSetIngredientsPhe.Value;
1089
    end;
1090
    // Tyr
1091
    if ClientDataSetInraAfzTyr.IsNull
1092
    then
1093
    begin
1094
      ClientDataSetIngredientsTyr.Clear;
1095
      ClientDataSetIngredientsTyr_MAT.Clear;
1096
      ClientDataSetIngredientsdTyr.Clear;
1097
      ClientDataSetIngredientsTyrd.Clear;
1098
    end
1099
    else
1100
    begin
1101
      ClientDataSetIngredientsTyr.Value := OutputAA(ClientDataSetInraAfzTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1102
      ClientDataSetIngredientsTyr_MAT.Value := InputAA(ClientDataSetIngredientsTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1103
      if ClientDataSetInraAfzdTyr.IsNull
1104
      then
1105
        ClientDataSetIngredientsdTyr.Value := dTyr * 100
1106
      else
1107
        ClientDataSetIngredientsdTyr.Value := ClientDataSetInraAfzdTyr.Value * 100;
1108
      ClientDataSetIngredientsTyrd.Value := ClientDataSetIngredientsdTyr.Value / 100 * ClientDataSetIngredientsTyr.Value;
1109
    end;
1110
    // Phe + Tyr
1111
    if ClientDataSetInraAfzPheTyr.IsNull
1112
    then
1113
    begin
1114
      ClientDataSetIngredientsPheTyr.Clear;
1115
      ClientDataSetIngredientsPheTyr_MAT.Clear;
1116
      ClientDataSetIngredientsdPheTyr.Clear;
1117
      ClientDataSetIngredientsPheTyrd.Clear;
1118
    end
1119
    else
1120
    begin
1121
      ClientDataSetIngredientsPheTyr.Value := OutputAA(ClientDataSetInraAfzPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1122
      ClientDataSetIngredientsPheTyr_MAT.Value := InputAA(ClientDataSetIngredientsPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1123
      if ClientDataSetInraAfzdPheTyr.IsNull
1124
      then
1125
        ClientDataSetIngredientsdPheTyr.Value := dPheTyr * 100
1126
      else
1127
        ClientDataSetIngredientsdPheTyr.Value := ClientDataSetInraAfzdPheTyr.Value * 100;
1128
      ClientDataSetIngredientsPheTyrd.Value := ClientDataSetIngredientsdPheTyr.Value / 100 * ClientDataSetIngredientsPheTyr.Value;
1129
    end;
1130
    // His
1131
    if ClientDataSetInraAfzHis.IsNull
1132
    then
1133
    begin
1134
      ClientDataSetIngredientsHis.Clear;
1135
      ClientDataSetIngredientsHis_MAT.Clear;
1136
      ClientDataSetIngredientsdHis.Clear;
1137
      ClientDataSetIngredientsHisd.Clear;
1138
    end
1139
    else
1140
    begin
1141
      ClientDataSetIngredientsHis.Value := OutputAA(ClientDataSetInraAfzHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1142
      ClientDataSetIngredientsHis_MAT.Value := InputAA(ClientDataSetIngredientsHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1143
      if ClientDataSetInraAfzdHis.IsNull
1144
      then
1145
        ClientDataSetIngredientsdHis.Value := dHis * 100
1146
      else
1147
        ClientDataSetIngredientsdHis.Value := ClientDataSetInraAfzdHis.Value * 100;
1148
      ClientDataSetIngredientsHisd.Value := ClientDataSetIngredientsdHis.Value / 100 * ClientDataSetIngredientsHis.Value;
1149
    end;
1150
    // Arg
1151
    if ClientDataSetInraAfzArg.IsNull
1152
    then
1153
    begin
1154
      ClientDataSetIngredientsArg.Clear;
1155
      ClientDataSetIngredientsArg_MAT.Clear;
1156
      ClientDataSetIngredientsdArg.Clear;
1157
      ClientDataSetIngredientsArgd.Clear;
1158
    end
1159
    else
1160
    begin
1161
      ClientDataSetIngredientsArg.Value := OutputAA(ClientDataSetInraAfzArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1162
      ClientDataSetIngredientsArg_MAT.Value := InputAA(ClientDataSetIngredientsArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1163
      if ClientDataSetInraAfzdArg.IsNull
1164
      then
1165
        ClientDataSetIngredientsdArg.Value := dArg * 100
1166
      else
1167
        ClientDataSetIngredientsdArg.Value := ClientDataSetInraAfzdArg.Value * 100;
1168
      ClientDataSetIngredientsArgd.Value := ClientDataSetIngredientsdArg.Value / 100 * ClientDataSetIngredientsArg.Value;
1169
    end;
1170
    // Ala
1171
    if ClientDataSetInraAfzAla.IsNull
1172
    then
1173
    begin
1174
      ClientDataSetIngredientsAla.Clear;
1175
      ClientDataSetIngredientsAla_MAT.Clear;
1176
      ClientDataSetIngredientsdAla.Clear;
1177
      ClientDataSetIngredientsAlad.Clear;
1178
    end
1179
    else
1180
    begin
1181
      ClientDataSetIngredientsAla.Value := OutputAA(ClientDataSetInraAfzAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1182
      ClientDataSetIngredientsAla_MAT.Value := InputAA(ClientDataSetIngredientsAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1183
      if ClientDataSetInraAfzdAla.IsNull
1184
      then
1185
        ClientDataSetIngredientsdAla.Value := dAla * 100
1186
      else
1187
        ClientDataSetIngredientsdAla.Value := ClientDataSetInraAfzdAla.Value * 100;
1188
      ClientDataSetIngredientsAlad.Value := ClientDataSetIngredientsdAla.Value / 100 * ClientDataSetIngredientsAla.Value;
1189
    end;
1190
    // Asp
1191
    if ClientDataSetInraAfzAsp.IsNull
1192
    then
1193
    begin
1194
      ClientDataSetIngredientsAsp.Clear;
1195
      ClientDataSetIngredientsAsp_MAT.Clear;
1196
      ClientDataSetIngredientsdAsp.Clear;
1197
      ClientDataSetIngredientsAspd.Clear;
1198
    end
1199
    else
1200
    begin
1201
      ClientDataSetIngredientsAsp.Value := OutputAA(ClientDataSetInraAfzAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1202
      ClientDataSetIngredientsAsp_MAT.Value := InputAA(ClientDataSetIngredientsAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1203
      if ClientDataSetInraAfzdAsp.IsNull
1204
      then
1205
        ClientDataSetIngredientsdAsp.Value := dAsp * 100
1206
      else
1207
        ClientDataSetIngredientsdAsp.Value := ClientDataSetInraAfzdAsp.Value * 100;
1208
      ClientDataSetIngredientsAspd.Value := ClientDataSetIngredientsdAsp.Value / 100 * ClientDataSetIngredientsAsp.Value;
1209
    end;
1210
    // Glu
1211
    if ClientDataSetInraAfzGlu.IsNull
1212
    then
1213
    begin
1214
      ClientDataSetIngredientsGlu.Clear;
1215
      ClientDataSetIngredientsGlu_MAT.Clear;
1216
      ClientDataSetIngredientsdGlu.Clear;
1217
      ClientDataSetIngredientsGlud.Clear;
1218
    end
1219
    else
1220
    begin
1221
      ClientDataSetIngredientsGlu.Value := OutputAA(ClientDataSetInraAfzGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1222
      ClientDataSetIngredientsGlu_MAT.Value := InputAA(ClientDataSetIngredientsGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1223
      if ClientDataSetInraAfzdGlu.IsNull
1224
      then
1225
        ClientDataSetIngredientsdGlu.Value := dGlu * 100
1226
      else
1227
        ClientDataSetIngredientsdGlu.Value := ClientDataSetInraAfzdGlu.Value * 100;
1228
      ClientDataSetIngredientsGlud.Value := ClientDataSetIngredientsdGlu.Value / 100 * ClientDataSetIngredientsGlu.Value;
1229
    end;
1230
    // Gly
1231
    if ClientDataSetInraAfzGly.IsNull
1232
    then
1233
    begin
1234
      ClientDataSetIngredientsGly.Clear;
1235
      ClientDataSetIngredientsGly_MAT.Clear;
1236
      ClientDataSetIngredientsdGly.Clear;
1237
      ClientDataSetIngredientsGlyd.Clear;
1238
    end
1239
    else
1240
    begin
1241
      ClientDataSetIngredientsGly.Value := OutputAA(ClientDataSetInraAfzGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1242
      ClientDataSetIngredientsGly_MAT.Value := InputAA(ClientDataSetIngredientsGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1243
      if ClientDataSetInraAfzdGly.IsNull
1244
      then
1245
        ClientDataSetIngredientsdGly.Value := dGly * 100
1246
      else
1247
        ClientDataSetIngredientsdGly.Value := ClientDataSetInraAfzdGly.Value * 100;
1248
      ClientDataSetIngredientsGlyd.Value := ClientDataSetIngredientsdGly.Value / 100 * ClientDataSetIngredientsGly.Value;
1249
    end;
1250
    // Ser
1251
    if ClientDataSetInraAfzSer.IsNull
1252
    then
1253
    begin
1254
      ClientDataSetIngredientsSer.Clear;
1255
      ClientDataSetIngredientsSer_MAT.Clear;
1256
      ClientDataSetIngredientsdSer.Clear;
1257
      ClientDataSetIngredientsSerd.Clear;
1258
    end
1259
    else
1260
    begin
1261
      ClientDataSetIngredientsSer.Value := OutputAA(ClientDataSetInraAfzSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1262
      ClientDataSetIngredientsSer_MAT.Value := InputAA(ClientDataSetIngredientsSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1263
      if ClientDataSetInraAfzdSer.IsNull
1264
      then
1265
        ClientDataSetIngredientsdSer.Value := dSer * 100
1266
      else
1267
        ClientDataSetIngredientsdSer.Value := ClientDataSetInraAfzdSer.Value * 100;
1268
      ClientDataSetIngredientsSerd.Value := ClientDataSetIngredientsdSer.Value / 100 * ClientDataSetIngredientsSer.Value;
1269
    end;
1270
    // Pro
1271
    if ClientDataSetInraAfzPro.IsNull
1272
    then
1273
    begin
1274
      ClientDataSetIngredientsPro.Clear;
1275
      ClientDataSetIngredientsPro_MAT.Clear;
1276
      ClientDataSetIngredientsdPro.Clear;
1277
      ClientDataSetIngredientsProd.Clear;
1278
    end
1279
    else
1280
    begin
1281
      ClientDataSetIngredientsPro.Value := OutputAA(ClientDataSetInraAfzPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1282
      ClientDataSetIngredientsPro_MAT.Value := InputAA(ClientDataSetIngredientsPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1283
      if ClientDataSetInraAfzdPro.IsNull
1284
      then
1285
        ClientDataSetIngredientsdPro.Value := dPro * 100
1286
      else
1287
        ClientDataSetIngredientsdPro.Value := ClientDataSetInraAfzdPro.Value * 100;
1288
      ClientDataSetIngredientsProd.Value := ClientDataSetIngredientsdPro.Value / 100 * ClientDataSetIngredientsPro.Value;
1289
    end;
1290
  end;
1291
  // Min?raux
1292
  if ClientDataSetInraAfzCa.IsNull
1293
  then
1294
    ClientDataSetIngredientsCa.Clear
1295
  else
1296
    ClientDataSetIngredientsCa.Value := OutputMinerals(ClientDataSetInraAfzCa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1297
  if ClientDataSetInraAfzP.IsNull
1298
  then
1299
    ClientDataSetIngredientsP.Clear
1300
  else
1301
    ClientDataSetIngredientsP.Value := OutputMinerals(ClientDataSetInraAfzP.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1302
  if ClientDataSetInraAfzNa.IsNull
1303
  then
1304
    ClientDataSetIngredientsNa.Clear
1305
  else
1306
    ClientDataSetIngredientsNa.Value := OutputMinerals(ClientDataSetInraAfzNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1307
  if ClientDataSetInraAfzK.IsNull
1308
  then
1309
    ClientDataSetIngredientsK.Clear
1310
  else
1311
    ClientDataSetIngredientsK.Value := OutputMinerals(ClientDataSetInraAfzK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1312
  if ClientDataSetInraAfzCl.IsNull
1313
  then
1314
    ClientDataSetIngredientsCl.Clear
1315
  else
1316
    ClientDataSetIngredientsCl.Value := OutputMinerals(ClientDataSetInraAfzCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1317
  if ClientDataSetIngredientsNa.IsNull or ClientDataSetIngredientsK.IsNull or ClientDataSetIngredientsCl.IsNull
1318
  then
1319
    ClientDataSetIngredientsBE.Clear
1320
  else
1321
    ClientDataSetIngredientsBE.Value := CalcBilanElectrolytique(InputMinerals(ClientDataSetIngredientsNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals));
1322
  if ClientDataSetIngredientsP.Value = 0
1323
  then // En l'absence de P, il n'y a pas de dP
1324
  begin
1325
    ClientDataSetIngredientsdP.Clear;
1326
    ClientDataSetIngredientsdPphy.Clear;
1327
  end
1328
  else
1329
  begin
1330
    if ClientDataSetInraAfzdP.IsNull
1331
    then // Par d?faut dP = 20%
1332
      ClientDataSetIngredientsdP.Value := 20
1333
    else
1334
      ClientDataSetIngredientsdP.Value := ClientDataSetInraAfzdP.Value * 100;
1335
    if ClientDataSetInraAfzdPphy.IsNull
1336
    then // Par d?faut dPphy = dP
1337
      ClientDataSetIngredientsdPphy.Value := ClientDataSetIngredientsdP.Value
1338
    else
1339
      ClientDataSetIngredientsdPphy.Value := ClientDataSetInraAfzdPphy.Value * 100;
1340
  end;
1341
  // Autres rapports
1342
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
1343
  then
1344
    ClientDataSetIngredientsLysd_ENc.Clear
1345
  else
1346
    if FormOptions.Energy = 0
1347
    then // g / MJ
1348
      if FormOptions.AA = 0
1349
      then // % (conversion)
1350
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value
1351
      else // g/kg
1352
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value
1353
    else // g / 1000 kcal
1354
      if FormOptions.AA = 0
1355
      then // % (conversion)
1356
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value * 1000
1357
      else // g/kg
1358
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value * 1000;
1359
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENt.IsNull or (ClientDataSetIngredientsENt.Value = 0)
1360
  then
1361
    ClientDataSetIngredientsLysd_ENt.Clear
1362
  else
1363
    if FormOptions.Energy = 0
1364
    then // g / MJ
1365
      if FormOptions.AA = 0
1366
      then // % (conversion)
1367
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value
1368
      else // g/kg
1369
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value
1370
    else // g / 1000 kcal
1371
      if FormOptions.AA = 0
1372
      then // % (conversion)
1373
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value * 1000
1374
      else // g/kg
1375
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value * 1000;
1376
end;
1377

    
1378
procedure TDataModuleDeclaration.CalcOriginal;
1379
// Renseigner l'enregistrement courant de ClientDataSetIngredients
1380
// ? partir de l'enregistrement courant de TableIngredients
1381
// en tenant compte des unit?s configur?es
1382
var
1383
  Nb: Integer;
1384
  Bonus, EB, dE, EDc, EDt, EM, EN, EqCB, EqADF, EqNDF, NUri, EUri, Res, ResD, ECH4, dMO, dN: Double;
1385
begin
1386
  // Analyse proximale -> valeurs saisies
1387
  RapMS := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MS']);
1388
  ClientDataSetIngredientsMS.Value := OutputProximal(RapMS, 1, 1, FormOptions.Proximal);
1389
  ClientDataSetIngredientsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
1390
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1391
  then
1392
    ClientDataSetIngredientsMM.Clear
1393
  else
1394
    ClientDataSetIngredientsMM.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1395
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1396
  then
1397
    ClientDataSetIngredientsMAT.Clear
1398
  else
1399
  begin
1400
    RapMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']);
1401
    ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
1402
  end;
1403
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1404
  then
1405
    ClientDataSetIngredientsMG.Clear
1406
  else
1407
    ClientDataSetIngredientsMG.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1408
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1409
  then
1410
    ClientDataSetIngredientsCB.Clear
1411
  else
1412
    ClientDataSetIngredientsCB.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1413
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1414
  then
1415
    ClientDataSetIngredientsNDF.Clear
1416
  else
1417
    ClientDataSetIngredientsNDF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1418
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1419
  then
1420
    ClientDataSetIngredientsADF.Clear
1421
  else
1422
    ClientDataSetIngredientsADF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1423
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
1424
  then
1425
    ClientDataSetIngredientsADL.Clear
1426
  else
1427
    ClientDataSetIngredientsADL.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADL']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1428
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1429
  then
1430
    ClientDataSetIngredientsAmidon.Clear
1431
  else
1432
    ClientDataSetIngredientsAmidon.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1433
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1434
  then
1435
    ClientDataSetIngredientsSucres.Clear
1436
  else
1437
    ClientDataSetIngredientsSucres.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1438
  // Energie
1439
  EB := 0;
1440
  dE := 0;
1441
  EDc := 0;
1442
  EDt := 0;
1443
  EM := 0;
1444
//  EN := 0;
1445
  NUri := 0;
1446
//  EUri := 0;
1447
  Res := 0;
1448
//  ResD := 0;
1449
//  ECH4 := 0;
1450
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['EB'])
1451
  then // EB calcul?e
1452
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1453
    or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1454
    or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1455
    then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1456
      ClientDataSetIngredientsEB.Clear
1457
    else
1458
    begin
1459
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1460
      then
1461
        EqCB := 0
1462
      else
1463
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1464
        then // Equation SANS sucres
1465
          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'])
1466
        else // Equation AVEC sucres
1467
          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']);
1468
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1469
      then
1470
        EqADF := 0
1471
      else
1472
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1473
        then // Equation SANS sucres
1474
          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'])
1475
        else // Equation AVEC sucres
1476
          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']);
1477
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1478
      then
1479
        EqNDF := 0
1480
      else
1481
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1482
        then // Equation SANS sucres
1483
          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'])
1484
        else // Equation AVEC sucres
1485
          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']);
1486
      Nb := 0;
1487
      if EqCB <> 0 then Inc(Nb);
1488
      if EqADF <> 0 then Inc(Nb);
1489
      if EqNDF <> 0 then Inc(Nb);
1490
      if Nb = 0
1491
      then // Equations sans valeur de fibre (ne devrait pas se produire)
1492
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1493
        then // Equation SANS amidon
1494
          if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1495
          then // Equation SANS sucres
1496
            EB := 17.64 + 4.78 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.80 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 15.88 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM'])
1497
          else // Equation AVEC sucres
1498
            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'])
1499
        else // Equation AVEC amidon
1500
          if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1501
          then // Equation SANS sucres
1502
            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'])
1503
          else // Equation AVEC sucres
1504
            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'])
1505
      else // Moyenne des ?quations significatives
1506
        EB := (EqCB + EqADF + EqNDF) / Nb;
1507
      ClientDataSetIngredientsEB.Value := OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy);
1508
    end
1509
  else // EB fournie par l'utilisateur
1510
  begin
1511
    EB := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['EB']);
1512
    ClientDataSetIngredientsEB.Value := OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy);
1513
  end;
1514
  Bonus := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Bonus']) * 100;
1515
  ClientDataSetIngredientsBonus.Value := Bonus;
1516
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1517
  then
1518
    EqCB := 0
1519
  else
1520
    EqCB := 90.1 - 157.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1521
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1522
  then
1523
    EqNDF := 0
1524
  else
1525
    EqNDF := 98.3 - 90.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1526
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1527
  then
1528
    EqADF := 0
1529
  else
1530
    EqADF := 90.8 - 143.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1531
  Nb := 0;
1532
  if EqCB <> 0 then Inc(Nb);
1533
  if EqNDF <> 0 then Inc(Nb);
1534
  if EqADF <> 0 then Inc(Nb);
1535
  if Nb = 0
1536
  then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1537
    ClientDataSetIngredientsdEc.Clear
1538
  else // Moyenne des ?quations significatives
1539
  begin
1540
    dE := (EqCB + EqNDF + EqADF) / Nb + Bonus;
1541
    ClientDataSetIngredientsdEc.Value := dE;
1542
  end;
1543
  if ClientDataSetIngredientsEB.IsNull or ClientDataSetIngredientsdEc.IsNull
1544
  then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1545
    ClientDataSetIngredientsEDc.Clear
1546
  else
1547
  begin
1548
    EDc := EB * dE / 100;
1549
    ClientDataSetIngredientsEDc.Value := OutputEnergy(EDc, RapMS, FormOptions.Expression, FormOptions.Energy);
1550
  end;
1551
  if ClientDataSetIngredientsEDc.IsNull
1552
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1553
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1554
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1555
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1556
  then // Informations insuffisantes pour calculer
1557
  begin
1558
    ClientDataSetIngredientsEMc.Clear;
1559
    ClientDataSetIngredientsEMc_EDc.Clear;
1560
  end
1561
  else
1562
  begin
1563
    NUri := 0.4 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) / 6.25;
1564
    EUri := CALORIE * (0.046 + 7.4 * NUri);
1565
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1566
    then // par d?faut, on estime les sucres ? 2 % MS
1567
      Res := 1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 0.02
1568
    else
1569
      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']);
1570
    ResD := 0.5 * Res;
1571
    ECH4 := CALORIE * 0.16 * ResD;
1572
    EM := EDc - EUri - ECH4;
1573
    ClientDataSetIngredientsEMc.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
1574
    if EDc = 0
1575
    then // Division par 0
1576
      ClientDataSetIngredientsEMc_EDc.Clear
1577
    else
1578
      ClientDataSetIngredientsEMc_EDc.Value := EM / EDc * 100;
1579
  end;
1580
  if ClientDataSetIngredientsEDc.IsNull
1581
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1582
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1583
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1584
  then // Informations insuffisantes pour calculer
1585
  begin
1586
    ClientDataSetIngredientsENc.Clear;
1587
    ClientDataSetIngredientsENc_EMc.Clear;
1588
  end
1589
  else
1590
  begin
1591
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1592
    then
1593
      EqCB := 0
1594
    else
1595
      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']);
1596
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1597
    then
1598
      EqNDF := 0
1599
    else
1600
      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']);
1601
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1602
    then
1603
      EqADF := 0
1604
    else
1605
      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']);
1606
    Nb := 0;
1607
    if EqCB <> 0 then Inc(Nb);
1608
    if EqNDF <> 0 then Inc(Nb);
1609
    if EqADF <> 0 then Inc(Nb);
1610
    if Nb = 0
1611
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1612
    begin
1613
      ClientDataSetIngredientsENc.Clear;
1614
      ClientDataSetIngredientsENc_EMc.Clear;
1615
    end
1616
    else // Moyenne des ?quations significatives
1617
    begin
1618
      EN := (EqCB + EqNDF + EqADF) / Nb;
1619
      ClientDataSetIngredientsENc.Value := OutputEnergy(EN, RapMS, FormOptions.Expression, FormOptions.Energy);
1620
      if EM = 0
1621
      then // Division par 0
1622
        ClientDataSetIngredientsENc_EMc.Clear
1623
      else
1624
        ClientDataSetIngredientsENc_EMc.Value := EN / EM * 100;
1625
    end;
1626
  end;
1627
  if ClientDataSetIngredientsEDc.IsNull
1628
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1629
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1630
  then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1631
  begin
1632
    ClientDataSetIngredientsEDt.Clear;
1633
    ClientDataSetIngredientsEDt_EDc.Clear;
1634
  end
1635
  else
1636
  begin
1637
    dMO := (7.45 + 0.949 * dE - 4.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT'])) / 100;
1638
    EDt := EDc + CALORIE * (1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM'])) * (1 - dMO);
1639
    ClientDataSetIngredientsEDt.Value := OutputEnergy(EDt, RapMS, FormOptions.Expression, FormOptions.Energy);
1640
    if EDc = 0
1641
    then // Division par 0
1642
      ClientDataSetIngredientsEDt_EDc.Clear
1643
    else
1644
      ClientDataSetIngredientsEDt_EDc.Value := EDt / EDc * 100;
1645
  end;
1646
  if ClientDataSetIngredientsEDt.IsNull
1647
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1648
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1649
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1650
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1651
  then // Informations insuffisantes pour calculer
1652
  begin
1653
    ClientDataSetIngredientsEMt.Clear;
1654
    ClientDataSetIngredientsEMt_EDt.Clear;
1655
  end
1656
  else
1657
  begin
1658
//    NUri := 0.4 * TableIngredients.FieldByName('MAT').AsFloat / 6.25;
1659
    EUri := CALORIE * (0.052 + 7.4 * NUri);
1660
//    if TableIngredients.FieldByName('Sucres').IsNull
1661
//    then // par d?faut, on estime les sucres ? 2 % MS
1662
//      Res := 1 - TableIngredients.FieldByName('MM').AsFloat - TableIngredients.FieldByName('MAT').AsFloat - TableIngredients.FieldByName('MG').AsFloat - TableIngredients.FieldByName('Amidon').AsFloat - 0.02
1663
//    else
1664
//      Res := 1 - TableIngredients.FieldByName('MM').AsFloat - TableIngredients.FieldByName('MAT').AsFloat - TableIngredients.FieldByName('MG').AsFloat - TableIngredients.FieldByName('Amidon').AsFloat - TableIngredients.FieldByName('Sucres').AsFloat;
1665
    ResD := 0.6 * Res;
1666
    ECH4 := CALORIE * 0.32 * ResD;
1667
    EM := EDt - EUri - ECH4;
1668
    ClientDataSetIngredientsEMt.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
1669
    if EDt = 0
1670
    then // Division par 0
1671
      ClientDataSetIngredientsEMt_EDt.Clear
1672
    else
1673
      ClientDataSetIngredientsEMt_EDt.Value := EM / EDt * 100;
1674
  end;
1675
  if ClientDataSetIngredientsEDt.IsNull
1676
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1677
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1678
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1679
  then // Informations insuffisantes pour calculer
1680
  begin
1681
    ClientDataSetIngredientsENt.Clear;
1682
    ClientDataSetIngredientsENt_EMt.Clear;
1683
  end
1684
  else
1685
  begin
1686
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1687
    then
1688
      EqCB := 0
1689
    else
1690
      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']);
1691
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1692
    then
1693
      EqNDF := 0
1694
    else
1695
      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']);
1696
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1697
    then
1698
      EqADF := 0
1699
    else
1700
      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']);
1701
    Nb := 0;
1702
    if EqCB <> 0 then Inc(Nb);
1703
    if EqNDF <> 0 then Inc(Nb);
1704
    if EqADF <> 0 then Inc(Nb);
1705
    if Nb = 0
1706
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1707
    begin
1708
      ClientDataSetIngredientsENt.Clear;
1709
      ClientDataSetIngredientsENt_EMt.Clear;
1710
    end
1711
    else // Moyenne des ?quations significatives
1712
    begin
1713
      EN := (EqCB + EqNDF + EqADF) / Nb;
1714
      ClientDataSetIngredientsENt.Value := OutputEnergy(EN, RapMS, FormOptions.Expression, FormOptions.Energy);
1715
      if EM = 0
1716
      then // Division par 0
1717
        ClientDataSetIngredientsENt_EMt.Clear
1718
      else
1719
        ClientDataSetIngredientsENt_EMt.Value := EN / EM * 100;
1720
    end;
1721
  end;
1722
  if ClientDataSetIngredientsEDt.IsNull or ClientDataSetIngredientsEB.IsNull or (ClientDataSetIngredientsEB.Value = 0)
1723
  then
1724
    ClientDataSetIngredientsdEt.Clear
1725
  else
1726
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsEDt.Value / ClientDataSetIngredientsEB.Value * 100;
1727
  if ClientDataSetIngredientsEMt.IsNull or ClientDataSetIngredientsEMc.IsNull or (ClientDataSetIngredientsEMc.Value = 0)
1728
  then
1729
    ClientDataSetIngredientsEMt_EMc.Clear
1730
  else
1731
    ClientDataSetIngredientsEMt_EMc.Value := ClientDataSetIngredientsEMt.Value / ClientDataSetIngredientsEMc.Value * 100;
1732
  if ClientDataSetIngredientsENt.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
1733
  then
1734
    ClientDataSetIngredientsENt_ENc.Clear
1735
  else
1736
    ClientDataSetIngredientsENt_ENc.Value := ClientDataSetIngredientsENt.Value / ClientDataSetIngredientsENc.Value * 100;
1737
  // Digestibilit? f?cale de l'azote
1738
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1739
  then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1740
  begin
1741
    ClientDataSetIngredientsdNc.Clear;
1742
    ClientDataSetIngredientsdNt.Clear;
1743
  end
1744
  else
1745
  begin
1746
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1747
    then
1748
      EqCB := 0
1749
    else
1750
      EqCB := 76.8 + 69.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 122.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1751
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1752
    then
1753
      EqNDF := 0
1754
    else
1755
      EqNDF := 81.3 + 79.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 69.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1756
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1757
    then
1758
      EqADF := 0
1759
    else
1760
      EqADF := 77.4 + 70.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 116.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1761
    Nb := 0;
1762
    if EqCB <> 0 then Inc(Nb);
1763
    if EqNDF <> 0 then Inc(Nb);
1764
    if EqADF <> 0 then Inc(Nb);
1765
    if Nb = 0
1766
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1767
      ClientDataSetIngredientsdNc.Clear
1768
    else // Moyenne des ?quations significatives
1769
    begin
1770
      dN := (EqCB + EqNDF + EqADF) / Nb;
1771
      ClientDataSetIngredientsdNc.Value := dN;
1772
    end;
1773
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1774
    then
1775
      EqCB := 0
1776
    else
1777
      EqCB := 77.9 + 77.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 87.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1778
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1779
   then
1780
      EqNDF := 0
1781
    else
1782
      EqNDF := 79.9 + 86.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 44.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1783
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1784
    then
1785
      EqADF := 0
1786
    else
1787
      EqADF := 78.3 + 78.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 83.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1788
    Nb := 0;
1789
    if EqCB <> 0 then Inc(Nb);
1790
    if EqNDF <> 0 then Inc(Nb);
1791
    if EqADF <> 0 then Inc(Nb);
1792
    if Nb = 0
1793
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1794
      ClientDataSetIngredientsdNt.Clear
1795
    else // Moyenne des ?quations significatives
1796
    begin
1797
      dN := (EqCB + EqNDF + EqADF) / Nb;
1798
      ClientDataSetIngredientsdNt.Value := dN;
1799
    end;
1800
  end;
1801
  // Acides amin?s
1802
  if RapMAT = 0
1803
  then // En l'absence de MAT, il n'y a pas d'acides amin?s
1804
  begin
1805
    // Teneurs
1806
    ClientDataSetIngredientsLys.Clear;
1807
    ClientDataSetIngredientsThr.Clear;
1808
    ClientDataSetIngredientsMet.Clear;
1809
    ClientDataSetIngredientsCys.Clear;
1810
    ClientDataSetIngredientsMetCys.Clear;
1811
    ClientDataSetIngredientsTrp.Clear;
1812
    ClientDataSetIngredientsIle.Clear;
1813
    ClientDataSetIngredientsVal.Clear;
1814
    ClientDataSetIngredientsLeu.Clear;
1815
    ClientDataSetIngredientsPhe.Clear;
1816
    ClientDataSetIngredientsTyr.Clear;
1817
    ClientDataSetIngredientsPheTyr.Clear;
1818
    ClientDataSetIngredientsHis.Clear;
1819
    ClientDataSetIngredientsArg.Clear;
1820
    ClientDataSetIngredientsAla.Clear;
1821
    ClientDataSetIngredientsAsp.Clear;
1822
    ClientDataSetIngredientsGlu.Clear;
1823
    ClientDataSetIngredientsGly.Clear;
1824
    ClientDataSetIngredientsSer.Clear;
1825
    ClientDataSetIngredientsPro.Clear;
1826
    // % MAT
1827
    ClientDataSetIngredientsLys_MAT.Clear;
1828
    ClientDataSetIngredientsThr_MAT.Clear;
1829
    ClientDataSetIngredientsMet_MAT.Clear;
1830
    ClientDataSetIngredientsCys_MAT.Clear;
1831
    ClientDataSetIngredientsMetCys_MAT.Clear;
1832
    ClientDataSetIngredientsTrp_MAT.Clear;
1833
    ClientDataSetIngredientsIle_MAT.Clear;
1834
    ClientDataSetIngredientsVal_MAT.Clear;
1835
    ClientDataSetIngredientsLeu_MAT.Clear;
1836
    ClientDataSetIngredientsPhe_MAT.Clear;
1837
    ClientDataSetIngredientsTyr_MAT.Clear;
1838
    ClientDataSetIngredientsPheTyr_MAT.Clear;
1839
    ClientDataSetIngredientsHis_MAT.Clear;
1840
    ClientDataSetIngredientsArg_MAT.Clear;
1841
    ClientDataSetIngredientsAla_MAT.Clear;
1842
    ClientDataSetIngredientsAsp_MAT.Clear;
1843
    ClientDataSetIngredientsGlu_MAT.Clear;
1844
    ClientDataSetIngredientsGly_MAT.Clear;
1845
    ClientDataSetIngredientsSer_MAT.Clear;
1846
    ClientDataSetIngredientsPro_MAT.Clear;
1847
    // Digestibilit?s
1848
    ClientDataSetIngredientsdLys.Clear;
1849
    ClientDataSetIngredientsdThr.Clear;
1850
    ClientDataSetIngredientsdMet.Clear;
1851
    ClientDataSetIngredientsdCys.Clear;
1852
    ClientDataSetIngredientsdMetCys.Clear;
1853
    ClientDataSetIngredientsdTrp.Clear;
1854
    ClientDataSetIngredientsdIle.Clear;
1855
    ClientDataSetIngredientsdVal.Clear;
1856
    ClientDataSetIngredientsdLeu.Clear;
1857
    ClientDataSetIngredientsdPhe.Clear;
1858
    ClientDataSetIngredientsdTyr.Clear;
1859
    ClientDataSetIngredientsdPheTyr.Clear;
1860
    ClientDataSetIngredientsdHis.Clear;
1861
    ClientDataSetIngredientsdArg.Clear;
1862
    ClientDataSetIngredientsdAla.Clear;
1863
    ClientDataSetIngredientsdAsp.Clear;
1864
    ClientDataSetIngredientsdGlu.Clear;
1865
    ClientDataSetIngredientsdGly.Clear;
1866
    ClientDataSetIngredientsdSer.Clear;
1867
    ClientDataSetIngredientsdPro.Clear;
1868
    // Teneurs digestibles
1869
    ClientDataSetIngredientsLysd.Clear;
1870
    ClientDataSetIngredientsThrd.Clear;
1871
    ClientDataSetIngredientsMetd.Clear;
1872
    ClientDataSetIngredientsCysd.Clear;
1873
    ClientDataSetIngredientsMetCysd.Clear;
1874
    ClientDataSetIngredientsTrpd.Clear;
1875
    ClientDataSetIngredientsIled.Clear;
1876
    ClientDataSetIngredientsVald.Clear;
1877
    ClientDataSetIngredientsLeud.Clear;
1878
    ClientDataSetIngredientsPhed.Clear;
1879
    ClientDataSetIngredientsTyrd.Clear;
1880
    ClientDataSetIngredientsPheTyrd.Clear;
1881
    ClientDataSetIngredientsHisd.Clear;
1882
    ClientDataSetIngredientsArgd.Clear;
1883
    ClientDataSetIngredientsAlad.Clear;
1884
    ClientDataSetIngredientsAspd.Clear;
1885
    ClientDataSetIngredientsGlud.Clear;
1886
    ClientDataSetIngredientsGlyd.Clear;
1887
    ClientDataSetIngredientsSerd.Clear;
1888
    ClientDataSetIngredientsProd.Clear;
1889
  end
1890
  else
1891
  begin
1892
    // Lys
1893
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Lys'])
1894
    then
1895
    begin
1896
      ClientDataSetIngredientsLys.Clear;
1897
      ClientDataSetIngredientsLys_MAT.Clear;
1898
      ClientDataSetIngredientsdLys.Clear;
1899
      ClientDataSetIngredientsLysd.Clear;
1900
    end
1901
    else
1902
    begin
1903
      ClientDataSetIngredientsLys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Lys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1904
      ClientDataSetIngredientsLys_MAT.Value := InputAA(ClientDataSetIngredientsLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1905
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dLys'])
1906
      then
1907
        ClientDataSetIngredientsdLys.Value := dLys * 100
1908
      else
1909
        ClientDataSetIngredientsdLys.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dLys']) * 100;
1910
      ClientDataSetIngredientsLysd.Value := ClientDataSetIngredientsdLys.Value * ClientDataSetIngredientsLys.Value / 100;
1911
    end;
1912
    // Thr
1913
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Thr'])
1914
    then
1915
    begin
1916
      ClientDataSetIngredientsThr.Clear;
1917
      ClientDataSetIngredientsThr_MAT.Clear;
1918
      ClientDataSetIngredientsdThr.Clear;
1919
      ClientDataSetIngredientsThrd.Clear;
1920
    end
1921
    else
1922
    begin
1923
      ClientDataSetIngredientsThr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Thr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1924
      ClientDataSetIngredientsThr_MAT.Value := InputAA(ClientDataSetIngredientsThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1925
      ClientDataSetIngredientsdThr.Value := dThr * 100;
1926
      ClientDataSetIngredientsThrd.Value := dThr * ClientDataSetIngredientsThr.Value;
1927
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dThr'])
1928
      then
1929
        ClientDataSetIngredientsdThr.Value := dThr * 100
1930
      else
1931
        ClientDataSetIngredientsdThr.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dThr']) * 100;
1932
      ClientDataSetIngredientsThrd.Value := ClientDataSetIngredientsdThr.Value * ClientDataSetIngredientsThr.Value / 100;
1933
    end;
1934
    // Met
1935
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Met'])
1936
    then
1937
    begin
1938
      ClientDataSetIngredientsMet.Clear;
1939
      ClientDataSetIngredientsMet_MAT.Clear;
1940
      ClientDataSetIngredientsdMet.Clear;
1941
      ClientDataSetIngredientsMetd.Clear;
1942
    end
1943
    else
1944
    begin
1945
      ClientDataSetIngredientsMet.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Met']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1946
      ClientDataSetIngredientsMet_MAT.Value := InputAA(ClientDataSetIngredientsMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1947
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dMet'])
1948
      then
1949
        ClientDataSetIngredientsdMet.Value := dMet * 100
1950
      else
1951
        ClientDataSetIngredientsdMet.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dMet']) * 100;
1952
      ClientDataSetIngredientsMetd.Value := ClientDataSetIngredientsdMet.Value * ClientDataSetIngredientsMet.Value / 100;
1953
    end;
1954
    // Cys
1955
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cys'])
1956
    then
1957
    begin
1958
      ClientDataSetIngredientsCys.Clear;
1959
      ClientDataSetIngredientsCys_MAT.Clear;
1960
      ClientDataSetIngredientsdCys.Clear;
1961
      ClientDataSetIngredientsCysd.Clear;
1962
    end
1963
    else
1964
    begin
1965
      ClientDataSetIngredientsCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1966
      ClientDataSetIngredientsCys_MAT.Value := InputAA(ClientDataSetIngredientsCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1967
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dCys'])
1968
      then
1969
        ClientDataSetIngredientsdCys.Value := dCys * 100
1970
      else
1971
        ClientDataSetIngredientsdCys.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dCys']) * 100;
1972
      ClientDataSetIngredientsCysd.Value := ClientDataSetIngredientsdCys.Value * ClientDataSetIngredientsCys.Value / 100;
1973
    end;
1974
    // Met + Cys
1975
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MetCys'])
1976
    then
1977
    begin
1978
      ClientDataSetIngredientsMetCys.Clear;
1979
      ClientDataSetIngredientsMetCys_MAT.Clear;
1980
      ClientDataSetIngredientsdMetCys.Clear;
1981
      ClientDataSetIngredientsMetCysd.Clear;
1982
    end
1983
    else
1984
    begin
1985
      ClientDataSetIngredientsMetCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MetCys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1986
      ClientDataSetIngredientsMetCys_MAT.Value := InputAA(ClientDataSetIngredientsMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1987
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dMetCys'])
1988
      then
1989
        ClientDataSetIngredientsdMetCys.Value := dMetCys * 100
1990
      else
1991
        ClientDataSetIngredientsdMetCys.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dMetCys']) * 100;
1992
      ClientDataSetIngredientsMetCysd.Value := ClientDataSetIngredientsdMetCys.Value * ClientDataSetIngredientsMetCys.Value / 100;
1993
    end;
1994
    // Trp
1995
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Trp'])
1996
    then
1997
    begin
1998
      ClientDataSetIngredientsTrp.Clear;
1999
      ClientDataSetIngredientsTrp_MAT.Clear;
2000
      ClientDataSetIngredientsdTrp.Clear;
2001
      ClientDataSetIngredientsTrpd.Clear;
2002
    end
2003
    else
2004
    begin
2005
      ClientDataSetIngredientsTrp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Trp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2006
      ClientDataSetIngredientsTrp_MAT.Value := InputAA(ClientDataSetIngredientsTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2007
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dTrp'])
2008
      then
2009
        ClientDataSetIngredientsdTrp.Value := dTrp * 100
2010
      else
2011
        ClientDataSetIngredientsdTrp.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dTrp']) * 100;
2012
      ClientDataSetIngredientsTrpd.Value := ClientDataSetIngredientsdTrp.Value * ClientDataSetIngredientsTrp.Value / 100;
2013
    end;
2014
    // Ile
2015
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ile'])
2016
    then
2017
    begin
2018
      ClientDataSetIngredientsIle.Clear;
2019
      ClientDataSetIngredientsIle_MAT.Clear;
2020
      ClientDataSetIngredientsdIle.Clear;
2021
      ClientDataSetIngredientsIled.Clear;
2022
    end
2023
    else
2024
    begin
2025
      ClientDataSetIngredientsIle.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ile']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2026
      ClientDataSetIngredientsIle_MAT.Value := InputAA(ClientDataSetIngredientsIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2027
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dIle'])
2028
      then
2029
        ClientDataSetIngredientsdIle.Value := dIle * 100
2030
      else
2031
        ClientDataSetIngredientsdIle.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dIle']) * 100;
2032
      ClientDataSetIngredientsIled.Value := ClientDataSetIngredientsdIle.Value * ClientDataSetIngredientsIle.Value / 100;
2033
    end;
2034
    // Val
2035
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Val'])
2036
    then
2037
    begin
2038
      ClientDataSetIngredientsVal.Clear;
2039
      ClientDataSetIngredientsVal_MAT.Clear;
2040
      ClientDataSetIngredientsdVal.Clear;
2041
      ClientDataSetIngredientsVald.Clear;
2042
    end
2043
    else
2044
    begin
2045
      ClientDataSetIngredientsVal.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Val']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2046
      ClientDataSetIngredientsVal_MAT.Value := InputAA(ClientDataSetIngredientsVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2047
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dVal'])
2048
      then
2049
        ClientDataSetIngredientsdVal.Value := dVal * 100
2050
      else
2051
        ClientDataSetIngredientsdVal.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dVal']) * 100;
2052
      ClientDataSetIngredientsVald.Value := ClientDataSetIngredientsdVal.Value * ClientDataSetIngredientsVal.Value / 100;
2053
    end;
2054
    // Leu
2055
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Leu'])
2056
    then
2057
    begin
2058
      ClientDataSetIngredientsLeu.Clear;
2059
      ClientDataSetIngredientsLeu_MAT.Clear;
2060
      ClientDataSetIngredientsdLeu.Clear;
2061
      ClientDataSetIngredientsLeud.Clear;
2062
    end
2063
    else
2064
    begin
2065
      ClientDataSetIngredientsLeu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Leu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2066
      ClientDataSetIngredientsLeu_MAT.Value := InputAA(ClientDataSetIngredientsLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2067
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dLeu'])
2068
      then
2069
        ClientDataSetIngredientsdLeu.Value := dLeu * 100
2070
      else
2071
        ClientDataSetIngredientsdLeu.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dLeu']) * 100;
2072
      ClientDataSetIngredientsLeud.Value := ClientDataSetIngredientsdLeu.Value * ClientDataSetIngredientsLeu.Value / 100;
2073
    end;
2074
    // Phe
2075
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Phe'])
2076
    then
2077
    begin
2078
      ClientDataSetIngredientsPhe.Clear;
2079
      ClientDataSetIngredientsPhe_MAT.Clear;
2080
      ClientDataSetIngredientsdPhe.Clear;
2081
      ClientDataSetIngredientsPhed.Clear;
2082
    end
2083
    else
2084
    begin
2085
      ClientDataSetIngredientsPhe.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Phe']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2086
      ClientDataSetIngredientsPhe_MAT.Value := InputAA(ClientDataSetIngredientsPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2087
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPhe'])
2088
      then
2089
        ClientDataSetIngredientsdPhe.Value := dPhe * 100
2090
      else
2091
        ClientDataSetIngredientsdPhe.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPhe']) * 100;
2092
      ClientDataSetIngredientsPhed.Value := ClientDataSetIngredientsdPhe.Value * ClientDataSetIngredientsPhe.Value / 100;
2093
    end;
2094
    // Tyr
2095
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Tyr'])
2096
    then
2097
    begin
2098
      ClientDataSetIngredientsTyr.Clear;
2099
      ClientDataSetIngredientsTyr_MAT.Clear;
2100
      ClientDataSetIngredientsdTyr.Clear;
2101
      ClientDataSetIngredientsTyrd.Clear;
2102
    end
2103
    else
2104
    begin
2105
      ClientDataSetIngredientsTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Tyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2106
      ClientDataSetIngredientsTyr_MAT.Value := InputAA(ClientDataSetIngredientsTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2107
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dTyr'])
2108
      then
2109
        ClientDataSetIngredientsdTyr.Value := dTyr * 100
2110
      else
2111
        ClientDataSetIngredientsdTyr.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dTyr']) * 100;
2112
      ClientDataSetIngredientsTyrd.Value := ClientDataSetIngredientsdTyr.Value * ClientDataSetIngredientsTyr.Value / 100;
2113
    end;
2114
    // Phe + Tyr
2115
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['PheTyr'])
2116
    then
2117
    begin
2118
      ClientDataSetIngredientsPheTyr.Clear;
2119
      ClientDataSetIngredientsPheTyr_MAT.Clear;
2120
      ClientDataSetIngredientsdPheTyr.Clear;
2121
      ClientDataSetIngredientsPheTyrd.Clear;
2122
    end
2123
    else
2124
    begin
2125
      ClientDataSetIngredientsPheTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['PheTyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2126
      ClientDataSetIngredientsPheTyr_MAT.Value := InputAA(ClientDataSetIngredientsPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2127
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPheTyr'])
2128
      then
2129
        ClientDataSetIngredientsdPheTyr.Value := dPheTyr * 100
2130
      else
2131
        ClientDataSetIngredientsdPheTyr.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPheTyr']) * 100;
2132
      ClientDataSetIngredientsPheTyrd.Value := ClientDataSetIngredientsdPheTyr.Value * ClientDataSetIngredientsPheTyr.Value / 100;
2133
    end;
2134
    // His
2135
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['His'])
2136
    then
2137
    begin
2138
      ClientDataSetIngredientsHis.Clear;
2139
      ClientDataSetIngredientsHis_MAT.Clear;
2140
      ClientDataSetIngredientsdHis.Clear;
2141
      ClientDataSetIngredientsHisd.Clear;
2142
    end
2143
    else
2144
    begin
2145
      ClientDataSetIngredientsHis.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['His']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2146
      ClientDataSetIngredientsHis_MAT.Value := InputAA(ClientDataSetIngredientsHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2147
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dHis'])
2148
      then
2149
        ClientDataSetIngredientsdHis.Value := dHis * 100
2150
      else
2151
        ClientDataSetIngredientsdHis.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dHis']) * 100;
2152
      ClientDataSetIngredientsHisd.Value := ClientDataSetIngredientsdHis.Value * ClientDataSetIngredientsHis.Value / 100;
2153
    end;
2154
    // Arg
2155
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Arg'])
2156
    then
2157
    begin
2158
      ClientDataSetIngredientsArg.Clear;
2159
      ClientDataSetIngredientsArg_MAT.Clear;
2160
      ClientDataSetIngredientsdArg.Clear;
2161
      ClientDataSetIngredientsArgd.Clear;
2162
    end
2163
    else
2164
    begin
2165
      ClientDataSetIngredientsArg.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Arg']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2166
      ClientDataSetIngredientsArg_MAT.Value := InputAA(ClientDataSetIngredientsArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2167
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dArg'])
2168
      then
2169
        ClientDataSetIngredientsdArg.Value := dArg * 100
2170
      else
2171
        ClientDataSetIngredientsdArg.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dArg']) * 100;
2172
      ClientDataSetIngredientsArgd.Value := ClientDataSetIngredientsdArg.Value * ClientDataSetIngredientsArg.Value / 100;
2173
    end;
2174
    // Ala
2175
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ala'])
2176
    then
2177
    begin
2178
      ClientDataSetIngredientsAla.Clear;
2179
      ClientDataSetIngredientsAla_MAT.Clear;
2180
      ClientDataSetIngredientsdAla.Clear;
2181
      ClientDataSetIngredientsAlad.Clear;
2182
    end
2183
    else
2184
    begin
2185
      ClientDataSetIngredientsAla.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ala']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2186
      ClientDataSetIngredientsAla_MAT.Value := InputAA(ClientDataSetIngredientsAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2187
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dAla'])
2188
      then
2189
        ClientDataSetIngredientsdAla.Value := dAla * 100
2190
      else
2191
        ClientDataSetIngredientsdAla.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dAla']) * 100;
2192
      ClientDataSetIngredientsAlad.Value := ClientDataSetIngredientsdAla.Value * ClientDataSetIngredientsAla.Value / 100;
2193
    end;
2194
    // Asp
2195
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Asp'])
2196
    then
2197
    begin
2198
      ClientDataSetIngredientsAsp.Clear;
2199
      ClientDataSetIngredientsAsp_MAT.Clear;
2200
      ClientDataSetIngredientsdAsp.Clear;
2201
      ClientDataSetIngredientsAspd.Clear;
2202
    end
2203
    else
2204
    begin
2205
      ClientDataSetIngredientsAsp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Asp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2206
      ClientDataSetIngredientsAsp_MAT.Value := InputAA(ClientDataSetIngredientsAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2207
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dAsp'])
2208
      then
2209
        ClientDataSetIngredientsdAsp.Value := dAsp * 100
2210
      else
2211
        ClientDataSetIngredientsdAsp.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dAsp']) * 100;
2212
      ClientDataSetIngredientsAspd.Value := ClientDataSetIngredientsdAsp.Value * ClientDataSetIngredientsAsp.Value / 100;
2213
    end;
2214
    // Glu
2215
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Glu'])
2216
    then
2217
    begin
2218
      ClientDataSetIngredientsGlu.Clear;
2219
      ClientDataSetIngredientsGlu_MAT.Clear;
2220
      ClientDataSetIngredientsdGlu.Clear;
2221
      ClientDataSetIngredientsGlud.Clear;
2222
    end
2223
    else
2224
    begin
2225
      ClientDataSetIngredientsGlu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Glu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2226
      ClientDataSetIngredientsGlu_MAT.Value := InputAA(ClientDataSetIngredientsGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2227
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dGlu'])
2228
      then
2229
        ClientDataSetIngredientsdGlu.Value := dGlu * 100
2230
      else
2231
        ClientDataSetIngredientsdGlu.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dGlu']) * 100;
2232
      ClientDataSetIngredientsGlud.Value := ClientDataSetIngredientsdGlu.Value * ClientDataSetIngredientsGlu.Value / 100;
2233
    end;
2234
    // Gly
2235
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Gly'])
2236
    then
2237
    begin
2238
      ClientDataSetIngredientsGly.Clear;
2239
      ClientDataSetIngredientsGly_MAT.Clear;
2240
      ClientDataSetIngredientsdGly.Clear;
2241
      ClientDataSetIngredientsGlyd.Clear;
2242
    end
2243
    else
2244
    begin
2245
      ClientDataSetIngredientsGly.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Gly']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2246
      ClientDataSetIngredientsGly_MAT.Value := InputAA(ClientDataSetIngredientsGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2247
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dGly'])
2248
      then
2249
        ClientDataSetIngredientsdGly.Value := dGly * 100
2250
      else
2251
        ClientDataSetIngredientsdGly.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dGly']) * 100;
2252
      ClientDataSetIngredientsGlyd.Value := ClientDataSetIngredientsdGly.Value * ClientDataSetIngredientsGly.Value / 100;
2253
    end;
2254
    // Ser
2255
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ser'])
2256
    then
2257
    begin
2258
      ClientDataSetIngredientsSer.Clear;
2259
      ClientDataSetIngredientsSer_MAT.Clear;
2260
      ClientDataSetIngredientsdSer.Clear;
2261
      ClientDataSetIngredientsSerd.Clear;
2262
    end
2263
    else
2264
    begin
2265
      ClientDataSetIngredientsSer.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ser']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2266
      ClientDataSetIngredientsSer_MAT.Value := InputAA(ClientDataSetIngredientsSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2267
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dSer'])
2268
      then
2269
        ClientDataSetIngredientsdSer.Value := dSer * 100
2270
      else
2271
        ClientDataSetIngredientsdSer.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dSer']) * 100;
2272
      ClientDataSetIngredientsSerd.Value := ClientDataSetIngredientsdSer.Value * ClientDataSetIngredientsSer.Value / 100;
2273
    end;
2274
    // Pro
2275
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Pro'])
2276
    then
2277
    begin
2278
      ClientDataSetIngredientsPro.Clear;
2279
      ClientDataSetIngredientsPro_MAT.Clear;
2280
      ClientDataSetIngredientsdPro.Clear;
2281
      ClientDataSetIngredientsProd.Clear;
2282
    end
2283
    else
2284
    begin
2285
      ClientDataSetIngredientsPro.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Pro']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2286
      ClientDataSetIngredientsPro_MAT.Value := InputAA(ClientDataSetIngredientsPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2287
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPro'])
2288
      then
2289
        ClientDataSetIngredientsdPro.Value := dPro * 100
2290
      else
2291
        ClientDataSetIngredientsdPro.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPro']) * 100;
2292
      ClientDataSetIngredientsProd.Value := ClientDataSetIngredientsdPro.Value * ClientDataSetIngredientsPro.Value / 100;
2293
    end;
2294
  end;
2295
  // Min?raux
2296
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
2297
  then
2298
    ClientDataSetIngredientsCa.Clear
2299
  else
2300
    ClientDataSetIngredientsCa.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ca']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2301
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
2302
  then
2303
    ClientDataSetIngredientsP.Clear
2304
  else
2305
    ClientDataSetIngredientsP.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['P']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2306
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Na'])
2307
  then
2308
    ClientDataSetIngredientsNa.Clear
2309
  else
2310
    ClientDataSetIngredientsNa.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Na']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2311
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['K'])
2312
  then
2313
    ClientDataSetIngredientsK.Clear
2314
  else
2315
    ClientDataSetIngredientsK.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['K']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2316
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cl'])
2317
  then
2318
    ClientDataSetIngredientsCl.Clear
2319
  else
2320
    ClientDataSetIngredientsCl.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cl']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2321
  if ClientDataSetIngredientsNa.IsNull or ClientDataSetIngredientsK.IsNull or ClientDataSetIngredientsCl.IsNull
2322
  then
2323
    ClientDataSetIngredientsBE.Clear
2324
  else
2325
    ClientDataSetIngredientsBE.Value := CalcBilanElectrolytique(InputMinerals(ClientDataSetIngredientsNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals));
2326
  if ClientDataSetIngredientsP.Value = 0
2327
  then // En l'absence de P, il n'y a pas de dP
2328
  begin
2329
    ClientDataSetIngredientsdP.Clear;
2330
    ClientDataSetIngredientsdPphy.Clear;
2331
  end
2332
  else
2333
  begin
2334
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
2335
    then // Par d?faut dP = 20%
2336
      ClientDataSetIngredientsdP.Value := 20
2337
    else
2338
      ClientDataSetIngredientsdP.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dP']) * 100;
2339
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
2340
    then // Par d?faut dPphy = dP
2341
      ClientDataSetIngredientsdPphy.Value := ClientDataSetIngredientsdP.Value
2342
    else
2343
      ClientDataSetIngredientsdPphy.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPphy']) * 100;
2344
  end;
2345
  // Autres rapports
2346
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
2347
  then
2348
    ClientDataSetIngredientsLysd_ENc.Clear
2349
  else
2350
    if FormOptions.Energy = 0
2351
    then // g / MJ
2352
      if FormOptions.AA = 0
2353
      then // % (conversion)
2354
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value
2355
      else // g/kg
2356
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value
2357
    else // g / 1000 kcal
2358
      if FormOptions.AA = 0
2359
      then // % (conversion)
2360
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value * 1000
2361
      else // g/kg
2362
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value * 1000;
2363
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENt.IsNull or (ClientDataSetIngredientsENt.Value = 0)
2364
  then
2365
    ClientDataSetIngredientsLysd_ENt.Clear
2366
  else
2367
    if FormOptions.Energy = 0
2368
    then // g / MJ
2369
      if FormOptions.AA = 0
2370
      then // % (conversion)
2371
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value
2372
      else // g/kg
2373
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value
2374
    else // g / 1000 kcal
2375
      if FormOptions.AA = 0
2376
      then // % (conversion)
2377
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value * 1000
2378
      else // g/kg
2379
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value * 1000;
2380
end;
2381

    
2382
procedure TDataModuleDeclaration.CalcCopy;
2383
// Renseigner l'enregistrement courant de ClientDataSetIngredients
2384
// ? partir de l'enregistrement courant de TableIngredients
2385
// en tenant compte des unit?s configur?es
2386
var
2387
  Nb: Integer;
2388
  Bonus, EB, dE, EDc, EDt, EM, EM_ED, EN_EM, dN: Double;
2389
  CorrMAT, CorrMG, CorrMM, CorrCB, CorrNDF, CorrADF, DiffMAT, DiffMG, DiffAmidon: Double;
2390
begin
2391
  // Analyse proximale
2392
  RapMS := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MS']);
2393
  ClientDataSetIngredientsMS.Value := OutputProximal(RapMS, 1, 1, FormOptions.Proximal);
2394
  ClientDataSetIngredientsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
2395
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
2396
  then
2397
    if ClientDataSetInraAfzMM.IsNull
2398
    then
2399
      ClientDataSetIngredientsMM.Clear
2400
    else
2401
      ClientDataSetIngredientsMM.Value := OutputProximal(ClientDataSetInraAfzMM.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2402
  else
2403
    ClientDataSetIngredientsMM.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2404
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2405
  then
2406
    if ClientDataSetInraAfzMAT.IsNull
2407
    then
2408
      ClientDataSetIngredientsMAT.Clear
2409
    else
2410
    begin
2411
      RapMAT := ClientDataSetInraAfzMAT.Value;
2412
      ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
2413
    end
2414
  else
2415
  begin
2416
    RapMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']);
2417
    ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
2418
  end;
2419
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2420
  then
2421
    if ClientDataSetInraAfzMG.IsNull
2422
    then
2423
      ClientDataSetIngredientsMG.Clear
2424
    else
2425
      ClientDataSetIngredientsMG.Value := OutputProximal(ClientDataSetInraAfzMG.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2426
  else
2427
    ClientDataSetIngredientsMG.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2428
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2429
  then
2430
    if ClientDataSetInraAfzCB.IsNull
2431
    then
2432
      ClientDataSetIngredientsCB.Clear
2433
    else
2434
      ClientDataSetIngredientsCB.Value := OutputProximal(ClientDataSetInraAfzCB.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2435
  else
2436
    ClientDataSetIngredientsCB.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2437
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2438
  then
2439
    if ClientDataSetInraAfzNDF.IsNull
2440
    then
2441
      ClientDataSetIngredientsNDF.Clear
2442
    else
2443
      ClientDataSetIngredientsNDF.Value := OutputProximal(ClientDataSetInraAfzNDF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2444
  else
2445
    ClientDataSetIngredientsNDF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2446
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2447
  then
2448
    if ClientDataSetInraAfzADF.IsNull
2449
    then
2450
      ClientDataSetIngredientsADF.Clear
2451
    else
2452
      ClientDataSetIngredientsADF.Value := OutputProximal(ClientDataSetInraAfzADF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2453
  else
2454
    ClientDataSetIngredientsADF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2455
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
2456
  then
2457
    if ClientDataSetInraAfzADL.IsNull
2458
    then
2459
      ClientDataSetIngredientsADL.Clear
2460
    else
2461
      ClientDataSetIngredientsADL.Value := OutputProximal(ClientDataSetInraAfzADL.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2462
  else
2463
    ClientDataSetIngredientsADL.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADL']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2464
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
2465
  then
2466
    if ClientDataSetInraAfzAmidon.IsNull
2467
    then
2468
      ClientDataSetIngredientsAmidon.Clear
2469
    else
2470
      ClientDataSetIngredientsAmidon.Value := OutputProximal(ClientDataSetInraAfzAmidon.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2471
  else
2472
    ClientDataSetIngredientsAmidon.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2473
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
2474
  then
2475
    if ClientDataSetInraAfzSucres.IsNull
2476
    then
2477
      ClientDataSetIngredientsSucres.Clear
2478
    else
2479
      ClientDataSetIngredientsSucres.Value := OutputProximal(ClientDataSetInraAfzSucres.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2480
  else
2481
    ClientDataSetIngredientsSucres.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2482
  // Energie -> Valeurs calcul?es
2483
  EB := ClientDataSetInraAfzEB.Value;
2484
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2485
  then
2486
    CorrMAT := 0
2487
  else
2488
    CorrMAT := CoefMAT * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value);
2489
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2490
  then
2491
    CorrMG := 0
2492
  else
2493
    CorrMG := CoefMG * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - ClientDataSetInraAfzMG.Value);
2494
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
2495
  then
2496
    CorrMM := 0
2497
  else
2498
    CorrMM := CoefMM * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - ClientDataSetInraAfzMM.Value);
2499
  // Correction : somme des corrections (born?e ? 0)
2500
  EB := Max(0, EB + CorrMAT + CorrMG + CorrMM);
2501
  ClientDataSetIngredientsEB.Value := OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy);
2502
  Bonus := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Bonus']) * 100;
2503
  ClientDataSetIngredientsBonus.Value := Bonus;
2504
  dE := ClientDataSetInraAfzdEc.Value * 100 + Bonus;
2505
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2506
  then
2507
    CorrCB := 0
2508
  else
2509
    CorrCB := ClientDataSetInraAfzCoefCB.Value * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - ClientDataSetInraAfzCB.Value) * 100;
2510
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2511
  then
2512
    CorrNDF := 0
2513
  else
2514
    CorrNDF := ClientDataSetInraAfzCoefNDF.Value * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - ClientDataSetInraAfzNDF.Value) * 100;
2515
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2516
  then
2517
    CorrADF := 0
2518
  else
2519
    CorrADF := ClientDataSetInraAfzCoefADF.Value * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - ClientDataSetInraAfzADF.Value) * 100;
2520
  Nb := 0;
2521
  if CorrCB <> 0 then Inc(Nb);
2522
  if CorrNDF <> 0 then Inc(Nb);
2523
  if CorrADF <> 0 then Inc(Nb);
2524
  if Nb > 0
2525
  then // Correction : moyenne des ?quations significatives (born?e ? 0)
2526
    dE := Max(0, dE + (CorrCB + CorrNDF + CorrADF) / Nb);
2527
  ClientDataSetIngredientsdEc.Value := dE;
2528
  EDc := EB * dE / 100;
2529
  ClientDataSetIngredientsEDc.Value := OutputEnergy(EDc, RapMS, FormOptions.Expression, FormOptions.Energy);
2530
  if EDc = 0
2531
  then // Division par 0
2532
  begin
2533
    ClientDataSetIngredientsEMc_EDc.Value := 0;
2534
    ClientDataSetIngredientsEMc.Value := 0;
2535
    EM := 0;
2536
  end
2537
  else
2538
  begin
2539
    EM_ED := ClientDataSetInraAfzEMc_EDc.Value;
2540
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2541
    then
2542
      DiffMAT := 0
2543
    else
2544
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2545
    if DiffMAT <> 0
2546
    then // Correction : variation de l'azote
2547
      EM_ED := EM_ED - 31.0 * 0.4 * DiffMAT / 6.25 / EDc;
2548
    ClientDataSetIngredientsEMc_EDc.Value := EM_ED * 100;
2549
    EM := EDc * EM_ED;
2550
    ClientDataSetIngredientsEMc.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2551
  end;
2552
  if EM = 0
2553
  then // Division par 0
2554
  begin
2555
    ClientDataSetIngredientsENc_EMc.Value := 0;
2556
    ClientDataSetIngredientsENc.Value := 0;
2557
  end
2558
  else
2559
  begin
2560
    EN_EM := ClientDataSetInraAfzENc_EMc.Value;
2561
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2562
    then
2563
      DiffMAT := 0
2564
    else
2565
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2566
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2567
    then
2568
      DiffMG := 0
2569
    else
2570
      DiffMG := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - ClientDataSetInraAfzMG.Value;
2571
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
2572
    then
2573
      DiffAmidon := 0
2574
    else
2575
      DiffAmidon := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - ClientDataSetInraAfzAmidon.Value;
2576
    if (DiffMAT <> 0) or (DiffMG <> 0) or (DiffAmidon <> 0)
2577
    then // Correction : variation MAT et/ou MG et/ou Amidon
2578
      EN_EM := EN_EM + (-2.8 * DiffMAT + 5.5 * DiffMG + 1.5 * DiffAmidon) / EM;
2579
    ClientDataSetIngredientsENc_EMc.Value := EN_EM * 100;
2580
    ClientDataSetIngredientsENc.Value := OutputEnergy(EM * EN_EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2581
  end;
2582
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
2583
  then
2584
    EDt := EDc + ClientDataSetInraAfza.Value * CALORIE * (1 - ClientDataSetInraAfzMM.Value) * (1 - ClientDataSetInraAfzb.Value * dE / 100)
2585
  else
2586
    EDt := EDc + ClientDataSetInraAfza.Value * CALORIE * (1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM'])) * (1 - ClientDataSetInraAfzb.Value * dE / 100);
2587
  ClientDataSetIngredientsEDt.Value := OutputEnergy(EDt, RapMS, FormOptions.Expression, FormOptions.Energy);
2588
  if EDc = 0
2589
  then // Division par 0
2590
    ClientDataSetIngredientsEDt_EDc.Value := 100
2591
  else
2592
    ClientDataSetIngredientsEDt_EDc.Value := EDt / EDc * 100;
2593
  if EDt = 0
2594
  then // Division par 0
2595
  begin
2596
    ClientDataSetIngredientsEMt_EDt.Value := 0;
2597
    ClientDataSetIngredientsEMt.Value := 0;
2598
    EM := 0;
2599
  end
2600
  else
2601
  begin
2602
    EM_ED := ClientDataSetInraAfzEMt_EDt.Value;
2603
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2604
    then
2605
      DiffMAT := 0
2606
    else
2607
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2608
    if DiffMAT <> 0
2609
    then // Correction : variation de l'azote
2610
      EM_ED := EM_ED - 31.0 * 0.4 * DiffMAT / 6.25 / EDt;
2611
    ClientDataSetIngredientsEMt_EDt.Value := EM_ED * 100;
2612
    EM := EDt * EM_ED;
2613
    ClientDataSetIngredientsEMt.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2614
  end;
2615
  if EM = 0
2616
  then // Division par 0
2617
  begin
2618
    ClientDataSetIngredientsENt_EMt.Value := 0;
2619
    ClientDataSetIngredientsENt.Value := 0;
2620
  end
2621
  else
2622
  begin
2623
    EN_EM := ClientDataSetInraAfzENt_EMt.Value;
2624
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2625
    then
2626
      DiffMAT := 0
2627
    else
2628
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2629
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2630
    then
2631
      DiffMG := 0
2632
    else
2633
      DiffMG := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - ClientDataSetInraAfzMG.Value;
2634
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
2635
    then
2636
      DiffAmidon := 0
2637
    else
2638
      DiffAmidon := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - ClientDataSetInraAfzAmidon.Value;
2639
    if (DiffMAT <> 0) or (DiffMG <> 0) or (DiffAmidon <> 0)
2640
    then // Correction : variation MAT et/ou MG et/ou Amidon
2641
      EN_EM := EN_EM + (-2.8 * DiffMAT + 5.5 * DiffMG + 1.5 * DiffAmidon) / EM;
2642
    ClientDataSetIngredientsENt_EMt.Value := EN_EM * 100;
2643
    ClientDataSetIngredientsENt.Value := OutputEnergy(EM * EN_EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2644
  end;
2645
  if ClientDataSetIngredientsEB.Value = 0
2646
  then
2647
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsdEc.Value
2648
  else
2649
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsEDt.Value / ClientDataSetIngredientsEB.Value * 100;
2650
  if ClientDataSetIngredientsEMc.Value = 0
2651
  then
2652
    ClientDataSetIngredientsEMt_EMc.Value := 100
2653
  else
2654
    ClientDataSetIngredientsEMt_EMc.Value := ClientDataSetIngredientsEMt.Value / ClientDataSetIngredientsEMc.Value * 100;
2655
  if ClientDataSetIngredientsENc.Value = 0
2656
  then
2657
    ClientDataSetIngredientsENt_ENc.Value := 100
2658
  else
2659
    ClientDataSetIngredientsENt_ENc.Value := ClientDataSetIngredientsENt.Value / ClientDataSetIngredientsENc.Value * 100;
2660
  // Digestibilit? f?cale de l'azote
2661
  if ClientDataSetInraAfzdNc.IsNull
2662
  then
2663
    ClientDataSetIngredientsdNc.Clear
2664
  else
2665
  begin
2666
    dN := ClientDataSetInraAfzdNc.Value * 100;
2667
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2668
    then
2669
      DiffMAT := 0
2670
    else
2671
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2672
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2673
    then
2674
      CorrCB := 0
2675
    else
2676
      CorrCB := 69.0 * DiffMAT - 122.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - ClientDataSetInraAfzCB.Value);
2677
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2678
    then
2679
      CorrNDF := 0
2680
    else
2681
      CorrNDF := 79.0 * DiffMAT - 69.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - ClientDataSetInraAfzNDF.Value);
2682
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2683
    then
2684
      CorrADF := 0
2685
    else
2686
      CorrADF := 70.0 * DiffMAT - 116.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - ClientDataSetInraAfzADF.Value);
2687
    Nb := 0;
2688
    if CorrCB <> 0 then Inc(Nb);
2689
    if CorrNDF <> 0 then Inc(Nb);
2690
    if CorrADF <> 0 then Inc(Nb);
2691
    if Nb > 0
2692
    then // Correction : moyenne des ?quations significatives
2693
      dN := dN + (CorrCB + CorrNDF + CorrADF) / Nb;
2694
    ClientDataSetIngredientsdNc.Value := dN;
2695
  end;
2696
  if ClientDataSetInraAfzdNt.IsNull
2697
  then
2698
    ClientDataSetIngredientsdNt.Clear
2699
  else
2700
  begin
2701
    dN := ClientDataSetInraAfzdNt.Value * 100;
2702
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2703
    then
2704
      DiffMAT := 0
2705
    else
2706
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2707
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2708
    then
2709
      CorrCB := 0
2710
    else
2711
      CorrCB := 77.0 * DiffMAT - 87.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - ClientDataSetInraAfzCB.Value);
2712
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2713
    then
2714
      CorrNDF := 0
2715
    else
2716
      CorrNDF := 86.0 * DiffMAT - 44.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - ClientDataSetInraAfzNDF.Value);
2717
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2718
    then
2719
      CorrADF := 0
2720
    else
2721
      CorrADF := 78.0 * DiffMAT - 83.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - ClientDataSetInraAfzADF.Value);
2722
    Nb := 0;
2723
    if CorrCB <> 0 then Inc(Nb);
2724
    if CorrNDF <> 0 then Inc(Nb);
2725
    if CorrADF <> 0 then Inc(Nb);
2726
    if Nb > 0
2727
    then // Correction : moyenne des ?quations significatives
2728
      dN := dN + (CorrCB + CorrNDF + CorrADF) / Nb;
2729
    ClientDataSetIngredientsdNt.Value := dN;
2730
  end;
2731
  // Acides amin?s
2732
  if RapMAT = 0
2733
  then // En l'absence de MAT, il n'y a pas d'acides amin?s
2734
  begin
2735
    // Teneurs
2736
    ClientDataSetIngredientsLys.Clear;
2737
    ClientDataSetIngredientsThr.Clear;
2738
    ClientDataSetIngredientsMet.Clear;
2739
    ClientDataSetIngredientsCys.Clear;
2740
    ClientDataSetIngredientsMetCys.Clear;
2741
    ClientDataSetIngredientsTrp.Clear;
2742
    ClientDataSetIngredientsIle.Clear;
2743
    ClientDataSetIngredientsVal.Clear;
2744
    ClientDataSetIngredientsLeu.Clear;
2745
    ClientDataSetIngredientsPhe.Clear;
2746
    ClientDataSetIngredientsTyr.Clear;
2747
    ClientDataSetIngredientsPheTyr.Clear;
2748
    ClientDataSetIngredientsHis.Clear;
2749
    ClientDataSetIngredientsArg.Clear;
2750
    ClientDataSetIngredientsAla.Clear;
2751
    ClientDataSetIngredientsAsp.Clear;
2752
    ClientDataSetIngredientsGlu.Clear;
2753
    ClientDataSetIngredientsGly.Clear;
2754
    ClientDataSetIngredientsSer.Clear;
2755
    ClientDataSetIngredientsPro.Clear;
2756
    // % MAT
2757
    ClientDataSetIngredientsLys_MAT.Clear;
2758
    ClientDataSetIngredientsThr_MAT.Clear;
2759
    ClientDataSetIngredientsMet_MAT.Clear;
2760
    ClientDataSetIngredientsCys_MAT.Clear;
2761
    ClientDataSetIngredientsMetCys_MAT.Clear;
2762
    ClientDataSetIngredientsTrp_MAT.Clear;
2763
    ClientDataSetIngredientsIle_MAT.Clear;
2764
    ClientDataSetIngredientsVal_MAT.Clear;
2765
    ClientDataSetIngredientsLeu_MAT.Clear;
2766
    ClientDataSetIngredientsPhe_MAT.Clear;
2767
    ClientDataSetIngredientsTyr_MAT.Clear;
2768
    ClientDataSetIngredientsPheTyr_MAT.Clear;
2769
    ClientDataSetIngredientsHis_MAT.Clear;
2770
    ClientDataSetIngredientsArg_MAT.Clear;
2771
    ClientDataSetIngredientsAla_MAT.Clear;
2772
    ClientDataSetIngredientsAsp_MAT.Clear;
2773
    ClientDataSetIngredientsGlu_MAT.Clear;
2774
    ClientDataSetIngredientsGly_MAT.Clear;
2775
    ClientDataSetIngredientsSer_MAT.Clear;
2776
    ClientDataSetIngredientsPro_MAT.Clear;
2777
    // Digestibilit?s
2778
    ClientDataSetIngredientsdLys.Clear;
2779
    ClientDataSetIngredientsdThr.Clear;
2780
    ClientDataSetIngredientsdMet.Clear;
2781
    ClientDataSetIngredientsdCys.Clear;
2782
    ClientDataSetIngredientsdMetCys.Clear;
2783
    ClientDataSetIngredientsdTrp.Clear;
2784
    ClientDataSetIngredientsdIle.Clear;
2785
    ClientDataSetIngredientsdVal.Clear;
2786
    ClientDataSetIngredientsdLeu.Clear;
2787
    ClientDataSetIngredientsdPhe.Clear;
2788
    ClientDataSetIngredientsdTyr.Clear;
2789
    ClientDataSetIngredientsdPheTyr.Clear;
2790
    ClientDataSetIngredientsdHis.Clear;
2791
    ClientDataSetIngredientsdArg.Clear;
2792
    ClientDataSetIngredientsdAla.Clear;
2793
    ClientDataSetIngredientsdAsp.Clear;
2794
    ClientDataSetIngredientsdGlu.Clear;
2795
    ClientDataSetIngredientsdGly.Clear;
2796
    ClientDataSetIngredientsdSer.Clear;
2797
    ClientDataSetIngredientsdPro.Clear;
2798
    // Teneurs digestibles
2799
    ClientDataSetIngredientsLysd.Clear;
2800
    ClientDataSetIngredientsThrd.Clear;
2801
    ClientDataSetIngredientsMetd.Clear;
2802
    ClientDataSetIngredientsCysd.Clear;
2803
    ClientDataSetIngredientsMetCysd.Clear;
2804
    ClientDataSetIngredientsTrpd.Clear;
2805
    ClientDataSetIngredientsIled.Clear;
2806
    ClientDataSetIngredientsVald.Clear;
2807
    ClientDataSetIngredientsLeud.Clear;
2808
    ClientDataSetIngredientsPhed.Clear;
2809
    ClientDataSetIngredientsTyrd.Clear;
2810
    ClientDataSetIngredientsPheTyrd.Clear;
2811
    ClientDataSetIngredientsHisd.Clear;
2812
    ClientDataSetIngredientsArgd.Clear;
2813
    ClientDataSetIngredientsAlad.Clear;
2814
    ClientDataSetIngredientsAspd.Clear;
2815
    ClientDataSetIngredientsGlud.Clear;
2816
    ClientDataSetIngredientsGlyd.Clear;
2817
    ClientDataSetIngredientsSerd.Clear;
2818
    ClientDataSetIngredientsProd.Clear;
2819
  end
2820
  else
2821
  begin
2822
    // Lys
2823
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Lys'])
2824
    and ClientDataSetInraAfzLys.IsNull
2825
    then
2826
    begin
2827
      ClientDataSetIngredientsLys.Clear;
2828
      ClientDataSetIngredientsLys_MAT.Clear;
2829
      ClientDataSetIngredientsdLys.Clear;
2830
      ClientDataSetIngredientsLysd.Clear;
2831
    end
2832
    else
2833
    begin
2834
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Lys'])
2835
      then
2836
        ClientDataSetIngredientsLys.Value := OutputAA(ClientDataSetInraAfzLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2837
      else
2838
        ClientDataSetIngredientsLys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Lys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2839
      ClientDataSetIngredientsLys_MAT.Value := InputAA(ClientDataSetIngredientsLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2840
      if ClientDataSetInraAfzdLys.IsNull
2841
      then
2842
        ClientDataSetIngredientsdLys.Value := dLys * 100
2843
      else
2844
        ClientDataSetIngredientsdLys.Value := ClientDataSetInraAfzdLys.Value * 100;
2845
      ClientDataSetIngredientsLysd.Value := ClientDataSetIngredientsdLys.Value / 100 * ClientDataSetIngredientsLys.Value;
2846
    end;
2847
    // Thr
2848
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Thr'])
2849
    and ClientDataSetInraAfzThr.IsNull
2850
    then
2851
    begin
2852
      ClientDataSetIngredientsThr.Clear;
2853
      ClientDataSetIngredientsThr_MAT.Clear;
2854
      ClientDataSetIngredientsdThr.Clear;
2855
      ClientDataSetIngredientsThrd.Clear;
2856
    end
2857
    else
2858
    begin
2859
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Thr'])
2860
      then
2861
        ClientDataSetIngredientsThr.Value := OutputAA(ClientDataSetInraAfzThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2862
      else
2863
        ClientDataSetIngredientsThr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Thr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2864
      ClientDataSetIngredientsThr_MAT.Value := InputAA(ClientDataSetIngredientsThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2865
      if ClientDataSetInraAfzdThr.IsNull
2866
      then
2867
        ClientDataSetIngredientsdThr.Value := dThr * 100
2868
      else
2869
        ClientDataSetIngredientsdThr.Value := ClientDataSetInraAfzdThr.Value * 100;
2870
      ClientDataSetIngredientsThrd.Value := ClientDataSetIngredientsdThr.Value / 100 * ClientDataSetIngredientsThr.Value;
2871
    end;
2872
    // Met
2873
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Met'])
2874
    and ClientDataSetInraAfzMet.IsNull
2875
    then
2876
    begin
2877
      ClientDataSetIngredientsMet.Clear;
2878
      ClientDataSetIngredientsMet_MAT.Clear;
2879
      ClientDataSetIngredientsdMet.Clear;
2880
      ClientDataSetIngredientsMetd.Clear;
2881
    end
2882
    else
2883
    begin
2884
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Met'])
2885
      then
2886
        ClientDataSetIngredientsMet.Value := OutputAA(ClientDataSetInraAfzMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2887
      else
2888
        ClientDataSetIngredientsMet.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Met']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2889
      ClientDataSetIngredientsMet_MAT.Value := InputAA(ClientDataSetIngredientsMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2890
      if ClientDataSetInraAfzdMet.IsNull
2891
      then
2892
        ClientDataSetIngredientsdMet.Value := dMet * 100
2893
      else
2894
        ClientDataSetIngredientsdMet.Value := ClientDataSetInraAfzdMet.Value * 100;
2895
      ClientDataSetIngredientsMetd.Value := ClientDataSetIngredientsdMet.Value / 100 * ClientDataSetIngredientsMet.Value;
2896
    end;
2897
    // Cys
2898
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cys'])
2899
    and ClientDataSetInraAfzCys.IsNull
2900
    then
2901
    begin
2902
      ClientDataSetIngredientsCys.Clear;
2903
      ClientDataSetIngredientsCys_MAT.Clear;
2904
      ClientDataSetIngredientsdCys.Clear;
2905
      ClientDataSetIngredientsCysd.Clear;
2906
    end
2907
    else
2908
    begin
2909
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cys'])
2910
      then
2911
        ClientDataSetIngredientsCys.Value := OutputAA(ClientDataSetInraAfzCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2912
      else
2913
        ClientDataSetIngredientsCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2914
      ClientDataSetIngredientsCys_MAT.Value := InputAA(ClientDataSetIngredientsCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2915
      if ClientDataSetInraAfzdCys.IsNull
2916
      then
2917
        ClientDataSetIngredientsdCys.Value := dCys * 100
2918
      else
2919
        ClientDataSetIngredientsdCys.Value := ClientDataSetInraAfzdCys.Value * 100;
2920
      ClientDataSetIngredientsCysd.Value := ClientDataSetIngredientsdCys.Value / 100 * ClientDataSetIngredientsCys.Value;
2921
    end;
2922
    // Met + Cys
2923
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MetCys'])
2924
    and ClientDataSetInraAfzMetCys.IsNull
2925
    then
2926
    begin
2927
      ClientDataSetIngredientsMetCys.Clear;
2928
      ClientDataSetIngredientsMetCys_MAT.Clear;
2929
      ClientDataSetIngredientsdMetCys.Clear;
2930
      ClientDataSetIngredientsMetCysd.Clear;
2931
    end
2932
    else
2933
    begin
2934
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MetCys'])
2935
      then
2936
        ClientDataSetIngredientsMetCys.Value := OutputAA(ClientDataSetInraAfzMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2937
      else
2938
        ClientDataSetIngredientsMetCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MetCys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2939
      ClientDataSetIngredientsMetCys_MAT.Value := InputAA(ClientDataSetIngredientsMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2940
      if ClientDataSetInraAfzdMetCys.IsNull
2941
      then
2942
        ClientDataSetIngredientsdMetCys.Value := dMetCys * 100
2943
      else
2944
        ClientDataSetIngredientsdMetCys.Value := ClientDataSetInraAfzdMetCys.Value * 100;
2945
      ClientDataSetIngredientsMetCysd.Value := ClientDataSetIngredientsdMetCys.Value / 100 * ClientDataSetIngredientsMetCys.Value;
2946
    end;
2947
    // Trp
2948
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Trp'])
2949
    and ClientDataSetInraAfzTrp.IsNull
2950
    then
2951
    begin
2952
      ClientDataSetIngredientsTrp.Clear;
2953
      ClientDataSetIngredientsTrp_MAT.Clear;
2954
      ClientDataSetIngredientsdTrp.Clear;
2955
      ClientDataSetIngredientsTrpd.Clear;
2956
    end
2957
    else
2958
    begin
2959
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Trp'])
2960
      then
2961
        ClientDataSetIngredientsTrp.Value := OutputAA(ClientDataSetInraAfzTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2962
      else
2963
        ClientDataSetIngredientsTrp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Trp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2964
      ClientDataSetIngredientsTrp_MAT.Value := InputAA(ClientDataSetIngredientsTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2965
      if ClientDataSetInraAfzdTrp.IsNull
2966
      then
2967
        ClientDataSetIngredientsdTrp.Value := dTrp * 100
2968
      else
2969
        ClientDataSetIngredientsdTrp.Value := ClientDataSetInraAfzdTrp.Value * 100;
2970
      ClientDataSetIngredientsTrpd.Value := ClientDataSetIngredientsdTrp.Value / 100 * ClientDataSetIngredientsTrp.Value;
2971
    end;
2972
    // Ile
2973
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ile'])
2974
    and ClientDataSetInraAfzIle.IsNull
2975
    then
2976
    begin
2977
      ClientDataSetIngredientsIle.Clear;
2978
      ClientDataSetIngredientsIle_MAT.Clear;
2979
      ClientDataSetIngredientsdIle.Clear;
2980
      ClientDataSetIngredientsIled.Clear;
2981
    end
2982
    else
2983
    begin
2984
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ile'])
2985
      then
2986
        ClientDataSetIngredientsIle.Value := OutputAA(ClientDataSetInraAfzIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2987
      else
2988
        ClientDataSetIngredientsIle.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ile']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2989
      ClientDataSetIngredientsIle_MAT.Value := InputAA(ClientDataSetIngredientsIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2990
      if ClientDataSetInraAfzdIle.IsNull
2991
      then
2992
        ClientDataSetIngredientsdIle.Value := dIle * 100
2993
      else
2994
        ClientDataSetIngredientsdIle.Value := ClientDataSetInraAfzdIle.Value * 100;
2995
      ClientDataSetIngredientsIled.Value := ClientDataSetIngredientsdIle.Value / 100 * ClientDataSetIngredientsIle.Value;
2996
    end;
2997
    // Val
2998
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Val'])
2999
    and ClientDataSetInraAfzVal.IsNull
3000
    then
3001
    begin
3002
      ClientDataSetIngredientsVal.Clear;
3003
      ClientDataSetIngredientsVal_MAT.Clear;
3004
      ClientDataSetIngredientsdVal.Clear;
3005
      ClientDataSetIngredientsVald.Clear;
3006
    end
3007
    else
3008
    begin
3009
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Val'])
3010
      then
3011
        ClientDataSetIngredientsVal.Value := OutputAA(ClientDataSetInraAfzVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3012
      else
3013
        ClientDataSetIngredientsVal.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Val']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3014
      ClientDataSetIngredientsVal_MAT.Value := InputAA(ClientDataSetIngredientsVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3015
      if ClientDataSetInraAfzdVal.IsNull
3016
      then
3017
        ClientDataSetIngredientsdVal.Value := dVal * 100
3018
      else
3019
        ClientDataSetIngredientsdVal.Value := ClientDataSetInraAfzdVal.Value * 100;
3020
      ClientDataSetIngredientsVald.Value := ClientDataSetIngredientsdVal.Value / 100 * ClientDataSetIngredientsVal.Value;
3021
    end;
3022
    // Leu
3023
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Leu'])
3024
    and ClientDataSetInraAfzLeu.IsNull
3025
    then
3026
    begin
3027
      ClientDataSetIngredientsLeu.Clear;
3028
      ClientDataSetIngredientsLeu_MAT.Clear;
3029
      ClientDataSetIngredientsdLeu.Clear;
3030
      ClientDataSetIngredientsLeud.Clear;
3031
    end
3032
    else
3033
    begin
3034
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Leu'])
3035
      then
3036
        ClientDataSetIngredientsLeu.Value := OutputAA(ClientDataSetInraAfzLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3037
      else
3038
        ClientDataSetIngredientsLeu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Leu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3039
      ClientDataSetIngredientsLeu_MAT.Value := InputAA(ClientDataSetIngredientsLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3040
      if ClientDataSetInraAfzdLeu.IsNull
3041
      then
3042
        ClientDataSetIngredientsdLeu.Value := dLeu * 100
3043
      else
3044
        ClientDataSetIngredientsdLeu.Value := ClientDataSetInraAfzdLeu.Value * 100;
3045
      ClientDataSetIngredientsLeud.Value := ClientDataSetIngredientsdLeu.Value / 100 * ClientDataSetIngredientsLeu.Value;
3046
    end;
3047
    // Phe
3048
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Phe'])
3049
    and ClientDataSetInraAfzPhe.IsNull
3050
    then
3051
    begin
3052
      ClientDataSetIngredientsPhe.Clear;
3053
      ClientDataSetIngredientsPhe_MAT.Clear;
3054
      ClientDataSetIngredientsdPhe.Clear;
3055
      ClientDataSetIngredientsPhed.Clear;
3056
    end
3057
    else
3058
    begin
3059
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Phe'])
3060
      then
3061
        ClientDataSetIngredientsPhe.Value := OutputAA(ClientDataSetInraAfzPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3062
      else
3063
        ClientDataSetIngredientsPhe.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Phe']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3064
      ClientDataSetIngredientsPhe_MAT.Value := InputAA(ClientDataSetIngredientsPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3065
      if ClientDataSetInraAfzdPhe.IsNull
3066
      then
3067
        ClientDataSetIngredientsdPhe.Value := dPhe * 100
3068
      else
3069
        ClientDataSetIngredientsdPhe.Value := ClientDataSetInraAfzdPhe.Value * 100;
3070
      ClientDataSetIngredientsPhed.Value := ClientDataSetIngredientsdPhe.Value / 100 * ClientDataSetIngredientsPhe.Value;
3071
    end;
3072
    // Tyr
3073
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Tyr'])
3074
    and ClientDataSetInraAfzTyr.IsNull
3075
    then
3076
    begin
3077
      ClientDataSetIngredientsTyr.Clear;
3078
      ClientDataSetIngredientsTyr_MAT.Clear;
3079
      ClientDataSetIngredientsdTyr.Clear;
3080
      ClientDataSetIngredientsTyrd.Clear;
3081
    end
3082
    else
3083
    begin
3084
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Tyr'])
3085
      then
3086
        ClientDataSetIngredientsTyr.Value := OutputAA(ClientDataSetInraAfzTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3087
      else
3088
        ClientDataSetIngredientsTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Tyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3089
      ClientDataSetIngredientsTyr_MAT.Value := InputAA(ClientDataSetIngredientsTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3090
      if ClientDataSetInraAfzdTyr.IsNull
3091
      then
3092
        ClientDataSetIngredientsdTyr.Value := dTyr * 100
3093
      else
3094
        ClientDataSetIngredientsdTyr.Value := ClientDataSetInraAfzdTyr.Value * 100;
3095
      ClientDataSetIngredientsTyrd.Value := ClientDataSetIngredientsdTyr.Value / 100 * ClientDataSetIngredientsTyr.Value;
3096
    end;
3097
    // Phe + Tyr
3098
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['PheTyr'])
3099
    and ClientDataSetInraAfzPheTyr.IsNull
3100
    then
3101
    begin
3102
      ClientDataSetIngredientsPheTyr.Clear;
3103
      ClientDataSetIngredientsPheTyr_MAT.Clear;
3104
      ClientDataSetIngredientsdPheTyr.Clear;
3105
      ClientDataSetIngredientsPheTyrd.Clear;
3106
    end
3107
    else
3108
    begin
3109
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['PheTyr'])
3110
      then
3111
        ClientDataSetIngredientsPheTyr.Value := OutputAA(ClientDataSetInraAfzPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3112
      else
3113
        ClientDataSetIngredientsPheTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['PheTyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3114
      ClientDataSetIngredientsPheTyr_MAT.Value := InputAA(ClientDataSetIngredientsPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3115
      if ClientDataSetInraAfzdPheTyr.IsNull
3116
      then
3117
        ClientDataSetIngredientsdPheTyr.Value := dPheTyr * 100
3118
      else
3119
        ClientDataSetIngredientsdPheTyr.Value := ClientDataSetInraAfzdPheTyr.Value * 100;
3120
      ClientDataSetIngredientsPheTyrd.Value := ClientDataSetIngredientsdPheTyr.Value / 100 * ClientDataSetIngredientsPheTyr.Value;
3121
    end;
3122
    // His
3123
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['His'])
3124
    and ClientDataSetInraAfzHis.IsNull
3125
    then
3126
    begin
3127
      ClientDataSetIngredientsHis.Clear;
3128
      ClientDataSetIngredientsHis_MAT.Clear;
3129
      ClientDataSetIngredientsdHis.Clear;
3130
      ClientDataSetIngredientsHisd.Clear;
3131
    end
3132
    else
3133
    begin
3134
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['His'])
3135
      then
3136
        ClientDataSetIngredientsHis.Value := OutputAA(ClientDataSetInraAfzHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3137
      else
3138
        ClientDataSetIngredientsHis.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['His']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3139
      ClientDataSetIngredientsHis_MAT.Value := InputAA(ClientDataSetIngredientsHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3140
      if ClientDataSetInraAfzdHis.IsNull
3141
      then
3142
        ClientDataSetIngredientsdHis.Value := dHis * 100
3143
      else
3144
        ClientDataSetIngredientsdHis.Value := ClientDataSetInraAfzdHis.Value * 100;
3145
      ClientDataSetIngredientsHisd.Value := ClientDataSetIngredientsdHis.Value / 100 * ClientDataSetIngredientsHis.Value;
3146
    end;
3147
    // Arg
3148
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Arg'])
3149
    and ClientDataSetInraAfzArg.IsNull
3150
    then
3151
    begin
3152
      ClientDataSetIngredientsArg.Clear;
3153
      ClientDataSetIngredientsArg_MAT.Clear;
3154
      ClientDataSetIngredientsdArg.Clear;
3155
      ClientDataSetIngredientsArgd.Clear;
3156
    end
3157
    else
3158
    begin
3159
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Arg'])
3160
      then
3161
        ClientDataSetIngredientsArg.Value := OutputAA(ClientDataSetInraAfzArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3162
      else
3163
        ClientDataSetIngredientsArg.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Arg']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3164
      ClientDataSetIngredientsArg_MAT.Value := InputAA(ClientDataSetIngredientsArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3165
      if ClientDataSetInraAfzdArg.IsNull
3166
      then
3167
        ClientDataSetIngredientsdArg.Value := dArg * 100
3168
      else
3169
        ClientDataSetIngredientsdArg.Value := ClientDataSetInraAfzdArg.Value * 100;
3170
      ClientDataSetIngredientsArgd.Value := ClientDataSetIngredientsdArg.Value / 100 * ClientDataSetIngredientsArg.Value;
3171
    end;
3172
    // Ala
3173
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ala'])
3174
    and ClientDataSetInraAfzAla.IsNull
3175
    then
3176
    begin
3177
      ClientDataSetIngredientsAla.Clear;
3178
      ClientDataSetIngredientsAla_MAT.Clear;
3179
      ClientDataSetIngredientsdAla.Clear;
3180
      ClientDataSetIngredientsAlad.Clear;
3181
    end
3182
    else
3183
    begin
3184
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ala'])
3185
      then
3186
        ClientDataSetIngredientsAla.Value := OutputAA(ClientDataSetInraAfzAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3187
      else
3188
        ClientDataSetIngredientsAla.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ala']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3189
      ClientDataSetIngredientsAla_MAT.Value := InputAA(ClientDataSetIngredientsAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3190
      if ClientDataSetInraAfzdAla.IsNull
3191
      then
3192
        ClientDataSetIngredientsdAla.Value := dAla * 100
3193
      else
3194
        ClientDataSetIngredientsdAla.Value := ClientDataSetInraAfzdAla.Value * 100;
3195
      ClientDataSetIngredientsAlad.Value := ClientDataSetIngredientsdAla.Value / 100 * ClientDataSetIngredientsAla.Value;
3196
    end;
3197
    // Asp
3198
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Asp'])
3199
    and ClientDataSetInraAfzAsp.IsNull
3200
    then
3201
    begin
3202
      ClientDataSetIngredientsAsp.Clear;
3203
      ClientDataSetIngredientsAsp_MAT.Clear;
3204
      ClientDataSetIngredientsdAsp.Clear;
3205
      ClientDataSetIngredientsAspd.Clear;
3206
    end
3207
    else
3208
    begin
3209
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Asp'])
3210
      then
3211
        ClientDataSetIngredientsAsp.Value := OutputAA(ClientDataSetInraAfzAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3212
      else
3213
        ClientDataSetIngredientsAsp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Asp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3214
      ClientDataSetIngredientsAsp_MAT.Value := InputAA(ClientDataSetIngredientsAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3215
      if ClientDataSetInraAfzdAsp.IsNull
3216
      then
3217
        ClientDataSetIngredientsdAsp.Value := dAsp * 100
3218
      else
3219
        ClientDataSetIngredientsdAsp.Value := ClientDataSetInraAfzdAsp.Value * 100;
3220
      ClientDataSetIngredientsAspd.Value := ClientDataSetIngredientsdAsp.Value / 100 * ClientDataSetIngredientsAsp.Value;
3221
    end;
3222
    // Glu
3223
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Glu'])
3224
    and ClientDataSetInraAfzGlu.IsNull
3225
    then
3226
    begin
3227
      ClientDataSetIngredientsGlu.Clear;
3228
      ClientDataSetIngredientsGlu_MAT.Clear;
3229
      ClientDataSetIngredientsdGlu.Clear;
3230
      ClientDataSetIngredientsGlud.Clear;
3231
    end
3232
    else
3233
    begin
3234
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Glu'])
3235
      then
3236
        ClientDataSetIngredientsGlu.Value := OutputAA(ClientDataSetInraAfzGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3237
      else
3238
        ClientDataSetIngredientsGlu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Glu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3239
      ClientDataSetIngredientsGlu_MAT.Value := InputAA(ClientDataSetIngredientsGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3240
      if ClientDataSetInraAfzdGlu.IsNull
3241
      then
3242
        ClientDataSetIngredientsdGlu.Value := dGlu * 100
3243
      else
3244
        ClientDataSetIngredientsdGlu.Value := ClientDataSetInraAfzdGlu.Value * 100;
3245
      ClientDataSetIngredientsGlud.Value := ClientDataSetIngredientsdGlu.Value / 100 * ClientDataSetIngredientsGlu.Value;
3246
    end;
3247
    // Gly
3248
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Gly'])
3249
    and ClientDataSetInraAfzGly.IsNull
3250
    then
3251
    begin
3252
      ClientDataSetIngredientsGly.Clear;
3253
      ClientDataSetIngredientsGly_MAT.Clear;
3254
      ClientDataSetIngredientsdGly.Clear;
3255
      ClientDataSetIngredientsGlyd.Clear;
3256
    end
3257
    else
3258
    begin
3259
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Gly'])
3260
      then
3261
        ClientDataSetIngredientsGly.Value := OutputAA(ClientDataSetInraAfzGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3262
      else
3263
        ClientDataSetIngredientsGly.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Gly']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3264
      ClientDataSetIngredientsGly_MAT.Value := InputAA(ClientDataSetIngredientsGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3265
      if ClientDataSetInraAfzdGly.IsNull
3266
      then
3267
        ClientDataSetIngredientsdGly.Value := dGly * 100
3268
      else
3269
        ClientDataSetIngredientsdGly.Value := ClientDataSetInraAfzdGly.Value * 100;
3270
      ClientDataSetIngredientsGlyd.Value := ClientDataSetIngredientsdGly.Value / 100 * ClientDataSetIngredientsGly.Value;
3271
    end;
3272
    // Ser
3273
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ser'])
3274
    and ClientDataSetInraAfzSer.IsNull
3275
    then
3276
    begin
3277
      ClientDataSetIngredientsSer.Clear;
3278
      ClientDataSetIngredientsSer_MAT.Clear;
3279
      ClientDataSetIngredientsdSer.Clear;
3280
      ClientDataSetIngredientsSerd.Clear;
3281
    end
3282
    else
3283
    begin
3284
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ser'])
3285
      then
3286
        ClientDataSetIngredientsSer.Value := OutputAA(ClientDataSetInraAfzSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3287
      else
3288
        ClientDataSetIngredientsSer.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ser']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3289
      ClientDataSetIngredientsSer_MAT.Value := InputAA(ClientDataSetIngredientsSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3290
      if ClientDataSetInraAfzdSer.IsNull
3291
      then
3292
        ClientDataSetIngredientsdSer.Value := dSer * 100
3293
      else
3294
        ClientDataSetIngredientsdSer.Value := ClientDataSetInraAfzdSer.Value * 100;
3295
      ClientDataSetIngredientsSerd.Value := ClientDataSetIngredientsdSer.Value / 100 * ClientDataSetIngredientsSer.Value;
3296
    end;
3297
    // Pro
3298
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Pro'])
3299
    and ClientDataSetInraAfzPro.IsNull
3300
    then
3301
    begin
3302
      ClientDataSetIngredientsPro.Clear;
3303
      ClientDataSetIngredientsPro_MAT.Clear;
3304
      ClientDataSetIngredientsdPro.Clear;
3305
      ClientDataSetIngredientsProd.Clear;
3306
    end
3307
    else
3308
    begin
3309
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Pro'])
3310
      then
3311
        ClientDataSetIngredientsPro.Value := OutputAA(ClientDataSetInraAfzPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3312
      else
3313
        ClientDataSetIngredientsPro.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Pro']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3314
      ClientDataSetIngredientsPro_MAT.Value := InputAA(ClientDataSetIngredientsPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3315
      if ClientDataSetInraAfzdPro.IsNull
3316
      then
3317
        ClientDataSetIngredientsdPro.Value := dPro * 100
3318
      else
3319
        ClientDataSetIngredientsdPro.Value := ClientDataSetInraAfzdPro.Value * 100;
3320
      ClientDataSetIngredientsProd.Value := ClientDataSetIngredientsdPro.Value / 100 * ClientDataSetIngredientsPro.Value;
3321
    end;
3322
  end;
3323
  // Min?raux
3324
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
3325
  then
3326
    if ClientDataSetInraAfzCa.IsNull
3327
    then
3328
      ClientDataSetIngredientsCa.Clear
3329
    else
3330
      ClientDataSetIngredientsCa.Value := OutputMinerals(ClientDataSetInraAfzCa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3331
  else
3332
    ClientDataSetIngredientsCa.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ca']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3333
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
3334
  then
3335
    if ClientDataSetInraAfzP.IsNull
3336
    then
3337
      ClientDataSetIngredientsP.Clear
3338
    else
3339
      ClientDataSetIngredientsP.Value := OutputMinerals(ClientDataSetInraAfzP.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3340
  else
3341
    ClientDataSetIngredientsP.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['P']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3342
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Na'])
3343
  then
3344
    if ClientDataSetInraAfzNa.IsNull
3345
    then
3346
      ClientDataSetIngredientsNa.Clear
3347
    else
3348
      ClientDataSetIngredientsNa.Value := OutputMinerals(ClientDataSetInraAfzNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3349
  else
3350
    ClientDataSetIngredientsNa.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Na']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3351
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['K'])
3352
  then
3353
    if ClientDataSetInraAfzK.IsNull
3354
    then
3355
      ClientDataSetIngredientsK.Clear
3356
    else
3357
      ClientDataSetIngredientsK.Value := OutputMinerals(ClientDataSetInraAfzK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3358
  else
3359
    ClientDataSetIngredientsK.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['K']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3360
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cl'])
3361
  then
3362
    if ClientDataSetInraAfzCl.IsNull
3363
    then
3364
      ClientDataSetIngredientsCl.Clear
3365
    else
3366
      ClientDataSetIngredientsCl.Value := OutputMinerals(ClientDataSetInraAfzCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3367
  else
3368
    ClientDataSetIngredientsCl.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cl']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3369
  if ClientDataSetIngredientsNa.IsNull or ClientDataSetIngredientsK.IsNull or ClientDataSetIngredientsCl.IsNull
3370
  then
3371
    ClientDataSetIngredientsBE.Clear
3372
  else
3373
    ClientDataSetIngredientsBE.Value := CalcBilanElectrolytique(InputMinerals(ClientDataSetIngredientsNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals));
3374
  if ClientDataSetIngredientsP.Value = 0
3375
  then // En l'absence de P, il n'y a pas de dP
3376
  begin
3377
    ClientDataSetIngredientsdP.Clear;
3378
    ClientDataSetIngredientsdPphy.Clear;
3379
  end
3380
  else
3381
  begin
3382
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
3383
    then
3384
      if ClientDataSetInraAfzdP.IsNull
3385
      then // Par d?faut dP = 20%
3386
        ClientDataSetIngredientsdP.Value := 20
3387
      else
3388
        ClientDataSetIngredientsdP.Value := ClientDataSetInraAfzdP.Value * 100
3389
    else
3390
      ClientDataSetIngredientsdP.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dP']) * 100;
3391
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
3392
    then
3393
      if ClientDataSetInraAfzdPphy.IsNull
3394
      then // Par d?faut dPphy = dP
3395
        ClientDataSetIngredientsdPphy.Value := ClientDataSetIngredientsdP.Value
3396
      else
3397
        ClientDataSetIngredientsdPphy.Value := ClientDataSetInraAfzdPphy.Value * 100
3398
    else
3399
      ClientDataSetIngredientsdPphy.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPphy']) * 100;
3400
  end;
3401
  // Autres rapports
3402
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
3403
  then
3404
    ClientDataSetIngredientsLysd_ENc.Clear
3405
  else
3406
    if FormOptions.Energy = 0
3407
    then // g / MJ
3408
      if FormOptions.AA = 0
3409
      then // % (conversion)
3410
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value
3411
      else // g/kg
3412
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value
3413
    else // g / 1000 kcal
3414
      if FormOptions.AA = 0
3415
      then // % (conversion)
3416
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value * 1000
3417
      else // g/kg
3418
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value * 1000;
3419
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENt.IsNull or (ClientDataSetIngredientsENt.Value = 0)
3420
  then
3421
    ClientDataSetIngredientsLysd_ENt.Clear
3422
  else
3423
    if FormOptions.Energy = 0
3424
    then // g / MJ
3425
      if FormOptions.AA = 0
3426
      then // % (conversion)
3427
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value
3428
      else // g/kg
3429
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value
3430
    else // g / 1000 kcal
3431
      if FormOptions.AA = 0
3432
      then // % (conversion)
3433
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value * 1000
3434
      else // g/kg
3435
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value * 1000;
3436
end;
3437

    
3438
procedure TDataModuleDeclaration.CalcFeed;
3439
// Renseigner l'enregistrement courant de ClientDataSetFeeds
3440
// ? partir de l'enregistrement courant de TableFeeds
3441
// en tenant compte des unit?s configur?es
3442
const
3443
  a = 1.026;
3444
  b = 0.00263;
3445
var
3446
  Ratio, CoefPhytase, PdEndo, PhytaseEndo, PhytaseMicro, PdMicro: Double;
3447
begin
3448
  if ClientDataSetComposition.RecordCount = 0
3449
  then // En l'absence de composition cent?simale toutes les valeurs sont nulles
3450
  begin
3451
    // Analyse proximale
3452
    ClientDataSetFeedsMS.Clear;
3453
    ClientDataSetFeedsMS2.Clear;
3454
    ClientDataSetFeedsMM.Clear;
3455
    ClientDataSetFeedsMAT.Clear;
3456
    ClientDataSetFeedsMG.Clear;
3457
    ClientDataSetFeedsCB.Clear;
3458
    ClientDataSetFeedsNDF.Clear;
3459
    ClientDataSetFeedsADF.Clear;
3460
    ClientDataSetFeedsADL.Clear;
3461
    ClientDataSetFeedsAmidon.Clear;
3462
    ClientDataSetFeedsSucres.Clear;
3463
    // Energie
3464
    ClientDataSetFeedsEB.Clear;
3465
    ClientDataSetFeedsEDc.Clear;
3466
    ClientDataSetFeedsEMc.Clear;
3467
    ClientDataSetFeedsENc.Clear;
3468
    ClientDataSetFeedsEDt.Clear;
3469
    ClientDataSetFeedsEMt.Clear;
3470
    ClientDataSetFeedsENt.Clear;
3471
    // Digestibilit? f?cale de l'azote
3472
    ClientDataSetFeedsdNc.Clear;
3473
    ClientDataSetFeedsdNt.Clear;
3474
    // Acides amin?s
3475
    ClientDataSetFeedsLys.Clear;
3476
    ClientDataSetFeedsThr.Clear;
3477
    ClientDataSetFeedsMet.Clear;
3478
    ClientDataSetFeedsCys.Clear;
3479
    ClientDataSetFeedsMetCys.Clear;
3480
    ClientDataSetFeedsTrp.Clear;
3481
    ClientDataSetFeedsIle.Clear;
3482
    ClientDataSetFeedsVal.Clear;
3483
    ClientDataSetFeedsLeu.Clear;
3484
    ClientDataSetFeedsPhe.Clear;
3485
    ClientDataSetFeedsTyr.Clear;
3486
    ClientDataSetFeedsPheTyr.Clear;
3487
    ClientDataSetFeedsHis.Clear;
3488
    ClientDataSetFeedsArg.Clear;
3489
    ClientDataSetFeedsAla.Clear;
3490
    ClientDataSetFeedsAsp.Clear;
3491
    ClientDataSetFeedsGlu.Clear;
3492
    ClientDataSetFeedsGly.Clear;
3493
    ClientDataSetFeedsSer.Clear;
3494
    ClientDataSetFeedsPro.Clear;
3495
    ClientDataSetFeedsLysd.Clear;
3496
    ClientDataSetFeedsThrd.Clear;
3497
    ClientDataSetFeedsMetd.Clear;
3498
    ClientDataSetFeedsCysd.Clear;
3499
    ClientDataSetFeedsMetCysd.Clear;
3500
    ClientDataSetFeedsTrpd.Clear;
3501
    ClientDataSetFeedsIled.Clear;
3502
    ClientDataSetFeedsVald.Clear;
3503
    ClientDataSetFeedsLeud.Clear;
3504
    ClientDataSetFeedsPhed.Clear;
3505
    ClientDataSetFeedsTyrd.Clear;
3506
    ClientDataSetFeedsPheTyrd.Clear;
3507
    ClientDataSetFeedsHisd.Clear;
3508
    ClientDataSetFeedsArgd.Clear;
3509
    ClientDataSetFeedsAlad.Clear;
3510
    ClientDataSetFeedsAspd.Clear;
3511
    ClientDataSetFeedsGlud.Clear;
3512
    ClientDataSetFeedsGlyd.Clear;
3513
    ClientDataSetFeedsSerd.Clear;
3514
    ClientDataSetFeedsProd.Clear;
3515
    // Min?raux
3516
    ClientDataSetFeedsCa.Clear;
3517
    ClientDataSetFeedsP.Clear;
3518
    ClientDataSetFeedsNa.Clear;
3519
    ClientDataSetFeedsK.Clear;
3520
    ClientDataSetFeedsCl.Clear;
3521
    ClientDataSetFeedsBE.Clear;
3522
    ClientDataSetFeedsPd.Clear;
3523
  end
3524
  else
3525
  begin
3526
    // COMPOSITON CHIMIQUE - Initialisation ? z?ro
3527
    // Analyse proximale
3528
    ClientDataSetFeedsMS.Value := 0;
3529
    ClientDataSetFeedsMM.Value := 0;
3530
    ClientDataSetFeedsMAT.Value := 0;
3531
    ClientDataSetFeedsMG.Value := 0;
3532
    ClientDataSetFeedsCB.Value := 0;
3533
    ClientDataSetFeedsNDF.Value := 0;
3534
    ClientDataSetFeedsADF.Value := 0;
3535
    ClientDataSetFeedsADL.Value := 0;
3536
    ClientDataSetFeedsAmidon.Value := 0;
3537
    ClientDataSetFeedsSucres.Value := 0;
3538
    // Energie
3539
    ClientDataSetFeedsEB.Value := 0;
3540
    ClientDataSetFeedsEDc.Value := 0;
3541
    ClientDataSetFeedsEMc.Value := 0;
3542
    ClientDataSetFeedsENc.Value := 0;
3543
    ClientDataSetFeedsEDt.Value := 0;
3544
    ClientDataSetFeedsEMt.Value := 0;
3545
    ClientDataSetFeedsENt.Value := 0;
3546
    // Digestibilit? f?cale de l'azote
3547
    ClientDataSetFeedsdNc.Value := 0;
3548
    ClientDataSetFeedsdNt.Value := 0;
3549
    // Acides amin?s
3550
    ClientDataSetFeedsLys.Value := 0;
3551
    ClientDataSetFeedsThr.Value := 0;
3552
    ClientDataSetFeedsMet.Value := 0;
3553
    ClientDataSetFeedsCys.Value := 0;
3554
    ClientDataSetFeedsMetCys.Value := 0;
3555
    ClientDataSetFeedsTrp.Value := 0;
3556
    ClientDataSetFeedsIle.Value := 0;
3557
    ClientDataSetFeedsVal.Value := 0;
3558
    ClientDataSetFeedsLeu.Value := 0;
3559
    ClientDataSetFeedsPhe.Value := 0;
3560
    ClientDataSetFeedsTyr.Value := 0;
3561
    ClientDataSetFeedsPheTyr.Value := 0;
3562
    ClientDataSetFeedsHis.Value := 0;
3563
    ClientDataSetFeedsArg.Value := 0;
3564
    ClientDataSetFeedsAla.Value := 0;
3565
    ClientDataSetFeedsAsp.Value := 0;
3566
    ClientDataSetFeedsGlu.Value := 0;
3567
    ClientDataSetFeedsGly.Value := 0;
3568
    ClientDataSetFeedsSer.Value := 0;
3569
    ClientDataSetFeedsPro.Value := 0;
3570
    ClientDataSetFeedsLysd.Value := 0;
3571
    ClientDataSetFeedsThrd.Value := 0;
3572
    ClientDataSetFeedsMetd.Value := 0;
3573
    ClientDataSetFeedsCysd.Value := 0;
3574
    ClientDataSetFeedsMetCysd.Value := 0;
3575
    ClientDataSetFeedsTrpd.Value := 0;
3576
    ClientDataSetFeedsIled.Value := 0;
3577
    ClientDataSetFeedsVald.Value := 0;
3578
    ClientDataSetFeedsLeud.Value := 0;
3579
    ClientDataSetFeedsPhed.Value := 0;
3580
    ClientDataSetFeedsTyrd.Value := 0;
3581
    ClientDataSetFeedsPheTyrd.Value := 0;
3582
    ClientDataSetFeedsHisd.Value := 0;
3583
    ClientDataSetFeedsArgd.Value := 0;
3584
    ClientDataSetFeedsAlad.Value := 0;
3585
    ClientDataSetFeedsAspd.Value := 0;
3586
    ClientDataSetFeedsGlud.Value := 0;
3587
    ClientDataSetFeedsGlyd.Value := 0;
3588
    ClientDataSetFeedsSerd.Value := 0;
3589
    ClientDataSetFeedsProd.Value := 0;
3590
    // Min?raux
3591
    ClientDataSetFeedsCa.Value := 0;
3592
    ClientDataSetFeedsP.Value := 0;
3593
    ClientDataSetFeedsNa.Value := 0;
3594
    ClientDataSetFeedsK.Value := 0;
3595
    ClientDataSetFeedsCl.Value := 0;
3596
    ClientDataSetFeedsPd.Value := 0;
3597
    PdEndo := 0;
3598
    ClientDataSetComposition.First;
3599
    while not ClientDataSetComposition.Eof do
3600
    begin
3601
      if ClientDataSetCompositionUser.Value
3602
      then
3603
        ClientDataSetIngredients.Filter := Format('Id = %d and User', [ClientDataSetCompositionIngredient.Value])
3604
      else
3605
        ClientDataSetIngredients.Filter := Format('Id = %d and not User', [ClientDataSetCompositionIngredient.Value]);
3606
      ClientDataSetIngredients.Filtered := True;
3607
      // COMPOSITON CHIMIQUE - Incr?mentation
3608
      Ratio := InputIncorporation(ClientDataSetCompositionLevel.Value, FormOptions.Incorporation);
3609
      ClientDataSetFeedsMS.Value := ClientDataSetFeedsMS.Value + ClientDataSetCompositionMS.Value * Ratio;
3610
      if FormOptions.Expression = 0
3611
      then // Conversion frais -> sec (mati?re s?che de la mati?re premi?re)
3612
        Ratio := Ratio / InputProximal(ClientDataSetIngredientsMS.Value, 1, 1, FormOptions.Proximal);
3613
      RapMS := InputProximal(ClientDataSetCompositionMS.Value, 1, 1, FormOptions.Proximal);
3614
      // Conversion sec -> frais (mati?re s?che de la composition)
3615
      Ratio := Ratio * RapMS;
3616
      // Analyse proximale
3617
      ClientDataSetFeedsMM.Value := ClientDataSetFeedsMM.Value + ClientDataSetIngredientsMM.Value * Ratio;
3618
      ClientDataSetFeedsMAT.Value := ClientDataSetFeedsMAT.Value + ClientDataSetIngredientsMAT.Value * Ratio;
3619
      if not ClientDataSetFeedsMG.IsNull
3620
      then
3621
        if ClientDataSetIngredientsMG.IsNull
3622
        then
3623
          ClientDataSetFeedsMG.Clear
3624
        else
3625
          ClientDataSetFeedsMG.Value := ClientDataSetFeedsMG.Value + ClientDataSetIngredientsMG.Value * Ratio;
3626
      if not ClientDataSetFeedsCB.IsNull
3627
      then
3628
        if ClientDataSetIngredientsCB.IsNull
3629
        then
3630
          ClientDataSetFeedsCB.Clear
3631
        else
3632
          ClientDataSetFeedsCB.Value := ClientDataSetFeedsCB.Value + ClientDataSetIngredientsCB.Value * Ratio;
3633
      if not ClientDataSetFeedsNDF.IsNull
3634
      then
3635
        if ClientDataSetIngredientsNDF.IsNull
3636
        then
3637
          ClientDataSetFeedsNDF.Clear
3638
        else
3639
          ClientDataSetFeedsNDF.Value := ClientDataSetFeedsNDF.Value + ClientDataSetIngredientsNDF.Value * Ratio;
3640
      if not ClientDataSetFeedsADF.IsNull
3641
      then
3642
        if ClientDataSetIngredientsADF.IsNull
3643
        then
3644
          ClientDataSetFeedsADF.Clear
3645
        else
3646
          ClientDataSetFeedsADF.Value := ClientDataSetFeedsADF.Value + ClientDataSetIngredientsADF.Value * Ratio;
3647
      if not ClientDataSetFeedsADL.IsNull
3648
      then
3649
        if ClientDataSetIngredientsADL.IsNull
3650
        then
3651
          ClientDataSetFeedsADL.Clear
3652
        else
3653
          ClientDataSetFeedsADL.Value := ClientDataSetFeedsADL.Value + ClientDataSetIngredientsADL.Value * Ratio;
3654
      if not ClientDataSetFeedsAmidon.IsNull
3655
      then
3656
        if ClientDataSetIngredientsAmidon.IsNull
3657
        then
3658
          ClientDataSetFeedsAmidon.Clear
3659
        else
3660
          ClientDataSetFeedsAmidon.Value := ClientDataSetFeedsAmidon.Value + ClientDataSetIngredientsAmidon.Value * Ratio;
3661
      if not ClientDataSetFeedsSucres.IsNull
3662
      then
3663
        if ClientDataSetIngredientsSucres.IsNull
3664
        then
3665
          ClientDataSetFeedsSucres.Clear
3666
        else
3667
          ClientDataSetFeedsSucres.Value := ClientDataSetFeedsSucres.Value + ClientDataSetIngredientsSucres.Value * Ratio;
3668
      // Energie
3669
      if not ClientDataSetFeedsEB.IsNull
3670
      then
3671
        if ClientDataSetIngredientsEB.IsNull
3672
        then
3673
          ClientDataSetFeedsEB.Clear
3674
        else
3675
          ClientDataSetFeedsEB.Value := ClientDataSetFeedsEB.Value + ClientDataSetIngredientsEB.Value * Ratio;
3676
      if not ClientDataSetFeedsEDc.IsNull
3677
      then
3678
        if ClientDataSetIngredientsEDc.IsNull
3679
        then
3680
          ClientDataSetFeedsEDc.Clear
3681
        else
3682
          ClientDataSetFeedsEDc.Value := ClientDataSetFeedsEDc.Value + ClientDataSetIngredientsEDc.Value * Ratio;
3683
      if not ClientDataSetFeedsEMc.IsNull
3684
      then
3685
        if ClientDataSetIngredientsEMc.IsNull
3686
        then
3687
          ClientDataSetFeedsEMc.Clear
3688
        else
3689
          ClientDataSetFeedsEMc.Value := ClientDataSetFeedsEMc.Value + ClientDataSetIngredientsEMc.Value * Ratio;
3690
      if not ClientDataSetFeedsENc.IsNull
3691
      then
3692
        if ClientDataSetIngredientsENc.IsNull
3693
        then
3694
          ClientDataSetFeedsENc.Clear
3695
        else
3696
          ClientDataSetFeedsENc.Value := ClientDataSetFeedsENc.Value + ClientDataSetIngredientsENc.Value * Ratio;
3697
      if not ClientDataSetFeedsEDt.IsNull
3698
      then
3699
        if ClientDataSetIngredientsEDt.IsNull
3700
        then
3701
          ClientDataSetFeedsEDt.Clear
3702
        else
3703
          ClientDataSetFeedsEDt.Value := ClientDataSetFeedsEDt.Value + ClientDataSetIngredientsEDt.Value * Ratio;
3704
      if not ClientDataSetFeedsEMt.IsNull
3705
      then
3706
        if ClientDataSetIngredientsEMt.IsNull
3707
        then
3708
          ClientDataSetFeedsEMt.Clear
3709
        else
3710
          ClientDataSetFeedsEMt.Value := ClientDataSetFeedsEMt.Value + ClientDataSetIngredientsEMt.Value * Ratio;
3711
      if not ClientDataSetFeedsENt.IsNull
3712
      then
3713
        if ClientDataSetIngredientsENt.IsNull
3714
        then
3715
          ClientDataSetFeedsENt.Clear
3716
        else
3717
          ClientDataSetFeedsENt.Value := ClientDataSetFeedsENt.Value + ClientDataSetIngredientsENt.Value * Ratio;
3718
      // Digestibilit? f?cale de l'azote
3719
      if not ClientDataSetFeedsdNc.IsNull
3720
      then
3721
        if ClientDataSetIngredientsdNc.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3722
        then // Ne devrait pas se produire
3723
          ClientDataSetFeedsdNc.Clear
3724
        else // MATd = MAT * dN
3725
          ClientDataSetFeedsdNc.Value := ClientDataSetFeedsdNc.Value + ClientDataSetIngredientsMAT.Value * ClientDataSetIngredientsdNc.Value / 100 * Ratio;
3726
      if not ClientDataSetFeedsdNt.IsNull
3727
      then
3728
        if ClientDataSetIngredientsdNt.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3729
        then // Ne devrait pas se produire
3730
          ClientDataSetFeedsdNt.Clear
3731
        else // MATd = MAT * dN
3732
          ClientDataSetFeedsdNt.Value := ClientDataSetFeedsdNt.Value + ClientDataSetIngredientsMAT.Value * ClientDataSetIngredientsdNt.Value / 100 * Ratio;
3733
      // Acides amin?s
3734
      if not ClientDataSetFeedsLys.IsNull
3735
      then
3736
        if ClientDataSetIngredientsLys.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3737
        then
3738
        begin
3739
          ClientDataSetFeedsLys.Clear;
3740
          ClientDataSetFeedsLysd.Clear;
3741
        end
3742
        else
3743
        begin
3744
          ClientDataSetFeedsLys.Value := ClientDataSetFeedsLys.Value + ClientDataSetIngredientsLys.Value * Ratio;
3745
          ClientDataSetFeedsLysd.Value := ClientDataSetFeedsLysd.Value + ClientDataSetIngredientsLysd.Value * Ratio;
3746
        end;
3747
      if not ClientDataSetFeedsThr.IsNull
3748
      then
3749
        if ClientDataSetIngredientsThr.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3750
        then
3751
        begin
3752
          ClientDataSetFeedsThr.Clear;
3753
          ClientDataSetFeedsThrd.Clear;
3754
        end
3755
        else
3756
        begin
3757
          ClientDataSetFeedsThr.Value := ClientDataSetFeedsThr.Value + ClientDataSetIngredientsThr.Value * Ratio;
3758
          ClientDataSetFeedsThrd.Value := ClientDataSetFeedsThrd.Value + ClientDataSetIngredientsThrd.Value * Ratio;
3759
        end;
3760
      if not ClientDataSetFeedsMet.IsNull
3761
      then
3762
        if ClientDataSetIngredientsMet.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3763
        then
3764
        begin
3765
          ClientDataSetFeedsMet.Clear;
3766
          ClientDataSetFeedsMetd.Clear;
3767
        end
3768
        else
3769
        begin
3770
          ClientDataSetFeedsMet.Value := ClientDataSetFeedsMet.Value + ClientDataSetIngredientsMet.Value * Ratio;
3771
          ClientDataSetFeedsMetd.Value := ClientDataSetFeedsMetd.Value + ClientDataSetIngredientsMetd.Value * Ratio;
3772
        end;
3773
      if not ClientDataSetFeedsCys.IsNull
3774
      then
3775
        if ClientDataSetIngredientsCys.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3776
        then
3777
        begin
3778
          ClientDataSetFeedsCys.Clear;
3779
          ClientDataSetFeedsCysd.Clear;
3780
        end
3781
        else
3782
        begin
3783
          ClientDataSetFeedsCys.Value := ClientDataSetFeedsCys.Value + ClientDataSetIngredientsCys.Value * Ratio;
3784
          ClientDataSetFeedsCysd.Value := ClientDataSetFeedsCysd.Value + ClientDataSetIngredientsCysd.Value * Ratio;
3785
        end;
3786
      if not ClientDataSetFeedsMetCys.IsNull
3787
      then
3788
        if ClientDataSetIngredientsMetCys.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3789
        then
3790
        begin
3791
          ClientDataSetFeedsMetCys.Clear;
3792
          ClientDataSetFeedsMetCysd.Clear;
3793
        end
3794
        else
3795
        begin
3796
          ClientDataSetFeedsMetCys.Value := ClientDataSetFeedsMetCys.Value + ClientDataSetIngredientsMetCys.Value * Ratio;
3797
          ClientDataSetFeedsMetCysd.Value := ClientDataSetFeedsMetCysd.Value + ClientDataSetIngredientsMetCysd.Value * Ratio;
3798
        end;
3799
      if not ClientDataSetFeedsTrp.IsNull
3800
      then
3801
        if ClientDataSetIngredientsTrp.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3802
        then
3803
        begin
3804
          ClientDataSetFeedsTrp.Clear;
3805
          ClientDataSetFeedsTrpd.Clear;
3806
        end
3807
        else
3808
        begin
3809
          ClientDataSetFeedsTrp.Value := ClientDataSetFeedsTrp.Value + ClientDataSetIngredientsTrp.Value * Ratio;
3810
          ClientDataSetFeedsTrpd.Value := ClientDataSetFeedsTrpd.Value + ClientDataSetIngredientsTrpd.Value * Ratio;
3811
        end;
3812
      if not ClientDataSetFeedsIle.IsNull
3813
      then
3814
        if ClientDataSetIngredientsIle.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3815
        then
3816
        begin
3817
          ClientDataSetFeedsIle.Clear;
3818
          ClientDataSetFeedsIled.Clear;
3819
        end
3820
        else
3821
        begin
3822
          ClientDataSetFeedsIle.Value := ClientDataSetFeedsIle.Value + ClientDataSetIngredientsIle.Value * Ratio;
3823
          ClientDataSetFeedsIled.Value := ClientDataSetFeedsIled.Value + ClientDataSetIngredientsIled.Value * Ratio;
3824
        end;
3825
      if not ClientDataSetFeedsVal.IsNull
3826
      then
3827
        if ClientDataSetIngredientsVal.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3828
        then
3829
        begin
3830
          ClientDataSetFeedsVal.Clear;
3831
          ClientDataSetFeedsVald.Clear;
3832
        end
3833
        else
3834
        begin
3835
          ClientDataSetFeedsVal.Value := ClientDataSetFeedsVal.Value + ClientDataSetIngredientsVal.Value * Ratio;
3836
          ClientDataSetFeedsVald.Value := ClientDataSetFeedsVald.Value + ClientDataSetIngredientsVald.Value * Ratio;
3837
        end;
3838
      if not ClientDataSetFeedsLeu.IsNull
3839
      then
3840
        if ClientDataSetIngredientsLeu.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3841
        then
3842
        begin
3843
          ClientDataSetFeedsLeu.Clear;
3844
          ClientDataSetFeedsLeud.Clear;
3845
        end
3846
        else
3847
        begin
3848
          ClientDataSetFeedsLeu.Value := ClientDataSetFeedsLeu.Value + ClientDataSetIngredientsLeu.Value * Ratio;
3849
          ClientDataSetFeedsLeud.Value := ClientDataSetFeedsLeud.Value + ClientDataSetIngredientsLeud.Value * Ratio;
3850
        end;
3851
      if not ClientDataSetFeedsPhe.IsNull
3852
      then
3853
        if ClientDataSetIngredientsPhe.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3854
        then
3855
        begin
3856
          ClientDataSetFeedsPhe.Clear;
3857
          ClientDataSetFeedsPhed.Clear;
3858
        end
3859
        else
3860
        begin
3861
          ClientDataSetFeedsPhe.Value := ClientDataSetFeedsPhe.Value + ClientDataSetIngredientsPhe.Value * Ratio;
3862
          ClientDataSetFeedsPhed.Value := ClientDataSetFeedsPhed.Value + ClientDataSetIngredientsPhed.Value * Ratio;
3863
        end;
3864
      if not ClientDataSetFeedsTyr.IsNull
3865
      then
3866
        if ClientDataSetIngredientsTyr.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3867
        then
3868
        begin
3869
          ClientDataSetFeedsTyr.Clear;
3870
          ClientDataSetFeedsTyrd.Clear;
3871
        end
3872
        else
3873
        begin
3874
          ClientDataSetFeedsTyr.Value := ClientDataSetFeedsTyr.Value + ClientDataSetIngredientsTyr.Value * Ratio;
3875
          ClientDataSetFeedsTyrd.Value := ClientDataSetFeedsTyrd.Value + ClientDataSetIngredientsTyrd.Value * Ratio;
3876
        end;
3877
      if not ClientDataSetFeedsPheTyr.IsNull
3878
      then
3879
        if ClientDataSetIngredientsPheTyr.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3880
        then
3881
        begin
3882
          ClientDataSetFeedsPheTyr.Clear;
3883
          ClientDataSetFeedsPheTyrd.Clear;
3884
        end
3885
        else
3886
        begin
3887
          ClientDataSetFeedsPheTyr.Value := ClientDataSetFeedsPheTyr.Value + ClientDataSetIngredientsPheTyr.Value * Ratio;
3888
          ClientDataSetFeedsPheTyrd.Value := ClientDataSetFeedsPheTyrd.Value + ClientDataSetIngredientsPheTyrd.Value * Ratio;
3889
        end;
3890
      if not ClientDataSetFeedsHis.IsNull
3891
      then
3892
        if ClientDataSetIngredientsHis.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3893
        then
3894
        begin
3895
          ClientDataSetFeedsHis.Clear;
3896
          ClientDataSetFeedsHisd.Clear;
3897
        end
3898
        else
3899
        begin
3900
          ClientDataSetFeedsHis.Value := ClientDataSetFeedsHis.Value + ClientDataSetIngredientsHis.Value * Ratio;
3901
          ClientDataSetFeedsHisd.Value := ClientDataSetFeedsHisd.Value + ClientDataSetIngredientsHisd.Value * Ratio;
3902
        end;
3903
      if not ClientDataSetFeedsArg.IsNull
3904
      then
3905
        if ClientDataSetIngredientsArg.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3906
        then
3907
        begin
3908
          ClientDataSetFeedsArg.Clear;
3909
          ClientDataSetFeedsArgd.Clear;
3910
        end
3911
        else
3912
        begin
3913
          ClientDataSetFeedsArg.Value := ClientDataSetFeedsArg.Value + ClientDataSetIngredientsArg.Value * Ratio;
3914
          ClientDataSetFeedsArgd.Value := ClientDataSetFeedsArgd.Value + ClientDataSetIngredientsArgd.Value * Ratio;
3915
        end;
3916
      if not ClientDataSetFeedsAla.IsNull
3917
      then
3918
        if ClientDataSetIngredientsAla.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3919
        then
3920
        begin
3921
          ClientDataSetFeedsAla.Clear;
3922
          ClientDataSetFeedsAlad.Clear;
3923
        end
3924
        else
3925
        begin
3926
          ClientDataSetFeedsAla.Value := ClientDataSetFeedsAla.Value + ClientDataSetIngredientsAla.Value * Ratio;
3927
          ClientDataSetFeedsAlad.Value := ClientDataSetFeedsAlad.Value + ClientDataSetIngredientsAlad.Value * Ratio;
3928
        end;
3929
      if not ClientDataSetFeedsAsp.IsNull
3930
      then
3931
        if ClientDataSetIngredientsAsp.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3932
        then
3933
        begin
3934
          ClientDataSetFeedsAsp.Clear;
3935
          ClientDataSetFeedsAspd.Clear;
3936
        end
3937
        else
3938
        begin
3939
          ClientDataSetFeedsAsp.Value := ClientDataSetFeedsAsp.Value + ClientDataSetIngredientsAsp.Value * Ratio;
3940
          ClientDataSetFeedsAspd.Value := ClientDataSetFeedsAspd.Value + ClientDataSetIngredientsAspd.Value * Ratio;
3941
        end;
3942
      if not ClientDataSetFeedsGlu.IsNull
3943
      then
3944
        if ClientDataSetIngredientsGlu.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3945
        then
3946
        begin
3947
          ClientDataSetFeedsGlu.Clear;
3948
          ClientDataSetFeedsGlud.Clear;
3949
        end
3950
        else
3951
        begin
3952
          ClientDataSetFeedsGlu.Value := ClientDataSetFeedsGlu.Value + ClientDataSetIngredientsGlu.Value * Ratio;
3953
          ClientDataSetFeedsGlud.Value := ClientDataSetFeedsGlud.Value + ClientDataSetIngredientsGlud.Value * Ratio;
3954
        end;
3955
      if not ClientDataSetFeedsGly.IsNull
3956
      then
3957
        if ClientDataSetIngredientsGly.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3958
        then
3959
        begin
3960
          ClientDataSetFeedsGly.Clear;
3961
          ClientDataSetFeedsGlyd.Clear;
3962
        end
3963
        else
3964
        begin
3965
          ClientDataSetFeedsGly.Value := ClientDataSetFeedsGly.Value + ClientDataSetIngredientsGly.Value * Ratio;
3966
          ClientDataSetFeedsGlyd.Value := ClientDataSetFeedsGlyd.Value + ClientDataSetIngredientsGlyd.Value * Ratio;
3967
        end;
3968
      if not ClientDataSetFeedsSer.IsNull
3969
      then
3970
        if ClientDataSetIngredientsSer.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3971
        then
3972
        begin
3973
          ClientDataSetFeedsSer.Clear;
3974
          ClientDataSetFeedsSerd.Clear;
3975
        end
3976
        else
3977
        begin
3978
          ClientDataSetFeedsSer.Value := ClientDataSetFeedsSer.Value + ClientDataSetIngredientsSer.Value * Ratio;
3979
          ClientDataSetFeedsSerd.Value := ClientDataSetFeedsSerd.Value + ClientDataSetIngredientsSerd.Value * Ratio;
3980
        end;
3981
      if not ClientDataSetFeedsPro.IsNull
3982
      then
3983
        if ClientDataSetIngredientsPro.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3984
        then
3985
        begin
3986
          ClientDataSetFeedsPro.Clear;
3987
          ClientDataSetFeedsProd.Clear;
3988
        end
3989
        else
3990
        begin
3991
          ClientDataSetFeedsPro.Value := ClientDataSetFeedsPro.Value + ClientDataSetIngredientsPro.Value * Ratio;
3992
          ClientDataSetFeedsProd.Value := ClientDataSetFeedsProd.Value + ClientDataSetIngredientsProd.Value * Ratio;
3993
        end;
3994
      // Min?raux
3995
      if not ClientDataSetFeedsCa.IsNull
3996
      then
3997
        if ClientDataSetIngredientsCa.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
3998
        then
3999
          ClientDataSetFeedsCa.Clear
4000
        else
4001
          ClientDataSetFeedsCa.Value := ClientDataSetFeedsCa.Value + ClientDataSetIngredientsCa.Value * Ratio;
4002
      if not ClientDataSetFeedsP.IsNull
4003
      then
4004
        if ClientDataSetIngredientsP.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
4005
        then
4006
          ClientDataSetFeedsP.Clear
4007
        else
4008
          ClientDataSetFeedsP.Value := ClientDataSetFeedsP.Value + ClientDataSetIngredientsP.Value * Ratio;
4009
      if not ClientDataSetFeedsNa.IsNull
4010
      then
4011
        if ClientDataSetIngredientsNa.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
4012
        then
4013
          ClientDataSetFeedsNa.Clear
4014
        else
4015
          ClientDataSetFeedsNa.Value := ClientDataSetFeedsNa.Value + ClientDataSetIngredientsNa.Value * Ratio;
4016
      if not ClientDataSetFeedsK.IsNull
4017
      then
4018
        if ClientDataSetIngredientsK.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
4019
        then
4020
          ClientDataSetFeedsK.Clear
4021
        else
4022
          ClientDataSetFeedsK.Value := ClientDataSetFeedsK.Value + ClientDataSetIngredientsK.Value * Ratio;
4023
      if not ClientDataSetFeedsCl.IsNull
4024
      then
4025
        if ClientDataSetIngredientsCl.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
4026
        then
4027
          ClientDataSetFeedsCl.Clear
4028
        else
4029
          ClientDataSetFeedsCl.Value := ClientDataSetFeedsCl.Value + ClientDataSetIngredientsCl.Value * Ratio;
4030
      if ClientDataSetFeedsNa.IsNull or ClientDataSetFeedsK.IsNull or ClientDataSetFeedsCl.IsNull
4031
      then
4032
        ClientDataSetFeedsBE.Clear
4033
      else
4034
        ClientDataSetFeedsBE.Value := CalcBilanElectrolytique(InputMinerals(ClientDataSetFeedsNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetFeedsK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetFeedsCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals));
4035
      if not ClientDataSetFeedsPd.IsNull
4036
      then
4037
        if ClientDataSetFeedsPresentation.Value = 0
4038
        then // Farine (dPphy)
4039
          if ClientDataSetIngredientsdPphy.IsNull and (ClientDataSetIngredientsP.Value <> 0) and (ClientDataSetIngredientsMM.Value <> 0)
4040
          then
4041
            ClientDataSetFeedsPd.Clear
4042
          else
4043
            ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value + (ClientDataSetIngredientsdPphy.Value / 100 * ClientDataSetIngredientsP.Value) * Ratio
4044
        else // Granul?s (dP)
4045
          if ClientDataSetIngredientsdP.IsNull and (ClientDataSetIngredientsP.Value <> 0) and (ClientDataSetIngredientsMM.Value <> 0)
4046
          then
4047
            ClientDataSetFeedsPd.Clear
4048
          else
4049
            ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value + (ClientDataSetIngredientsdP.Value / 100 * ClientDataSetIngredientsP.Value) * Ratio;
4050
      PdEndo := PdEndo + ((ClientDataSetIngredientsdPphy.Value - ClientDataSetIngredientsdP.Value) / 100 * ClientDataSetIngredientsP.Value) * Ratio;
4051
      ClientDataSetIngredients.Filtered := False;
4052
      ClientDataSetIngredients.Filter := '';
4053
      ClientDataSetComposition.Next;
4054
    end;
4055
    // Phytase
4056
    if not TableFeeds.FieldIsNull(TableFeeds.FieldIndex['Phytase'])
4057
    and not ClientDataSetFeedsPd.IsNull
4058
    then // Phosphore digestible lib?r? par la phytase
4059
    begin
4060
      PhytaseMicro := ClientDataSetFeedsPhytaseIncorporation.Value;
4061
      ClientDataSetPhytase.Locate('Id', ClientDataSetFeedsPhytaseId.Value, []);
4062
      CoefPhytase := ClientDataSetPhytaseCoef.Value;
4063
      if ClientDataSetFeedsPresentation.Value = 0
4064
      then // Farine (dPphy)
4065
      begin
4066
        if FormOptions.Minerals = 0
4067
        then // Conversion % -> g/kg
4068
          PdEndo := PdEndo / 100 * 1000;
4069
        PdEndo := Min(PdEndo, 0.4); // Limiter ? 0.4 g/kg
4070
        PhytaseEndo := -Ln(1 - PdEndo / a) / (b * CoefPhytase);
4071
        PdMicro := a * (1 - Exp(-b * (PhytaseMicro + PhytaseEndo) * CoefPhytase))
4072
          - a * (1 - Exp(-b * PhytaseEndo * CoefPhytase));
4073
      end
4074
      else // Granul?s (dP)
4075
        PdMicro := a * (1 - Exp(-b * PhytaseMicro * CoefPhytase));
4076
      if FormOptions.Minerals = 0
4077
      then // Conversion g/kg -> %
4078
        PdMicro := PdMicro / 1000 * 100;
4079
      ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value + PdMicro;
4080
    end;
4081
    RapMS := InputProximal(ClientDataSetFeedsMS.Value, 1, 1, FormOptions.Proximal);
4082
    ClientDataSetFeedsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
4083
    if FormOptions.Expression = 1
4084
    then // Conversion frais -> sec (mati?re s?che du r?gime)
4085
    begin
4086
      // Analyse proximale
4087
      ClientDataSetFeedsMM.Value := ClientDataSetFeedsMM.Value / RapMS;
4088
      ClientDataSetFeedsMAT.Value := ClientDataSetFeedsMAT.Value / RapMS;
4089
      if not ClientDataSetFeedsMG.IsNull
4090
      then
4091
        ClientDataSetFeedsMG.Value := ClientDataSetFeedsMG.Value / RapMS;
4092
      if not ClientDataSetFeedsCB.IsNull
4093
      then
4094
        ClientDataSetFeedsCB.Value := ClientDataSetFeedsCB.Value / RapMS;
4095
      if not ClientDataSetFeedsNDF.IsNull
4096
      then
4097
        ClientDataSetFeedsNDF.Value := ClientDataSetFeedsNDF.Value / RapMS;
4098
      if not ClientDataSetFeedsADF.IsNull
4099
      then
4100
        ClientDataSetFeedsADF.Value := ClientDataSetFeedsADF.Value / RapMS;
4101
      if not ClientDataSetFeedsADL.IsNull
4102
      then
4103
        ClientDataSetFeedsADL.Value := ClientDataSetFeedsADL.Value / RapMS;
4104
      if not ClientDataSetFeedsAmidon.IsNull
4105
      then
4106
        ClientDataSetFeedsAmidon.Value := ClientDataSetFeedsAmidon.Value / RapMS;
4107
      if not ClientDataSetFeedsSucres.IsNull
4108
      then
4109
        ClientDataSetFeedsSucres.Value := ClientDataSetFeedsSucres.Value / RapMS;
4110
      // Energie
4111
      if not ClientDataSetFeedsEB.IsNull
4112
      then
4113
        ClientDataSetFeedsEB.Value := ClientDataSetFeedsEB.Value / RapMS;
4114
      if not ClientDataSetFeedsEDc.IsNull
4115
      then
4116
        ClientDataSetFeedsEDc.Value := ClientDataSetFeedsEDc.Value / RapMS;
4117
      if not ClientDataSetFeedsEMc.IsNull
4118
      then
4119
        ClientDataSetFeedsEMc.Value := ClientDataSetFeedsEMc.Value / RapMS;
4120
      if not ClientDataSetFeedsENc.IsNull
4121
      then
4122
        ClientDataSetFeedsENc.Value := ClientDataSetFeedsENc.Value / RapMS;
4123
      if not ClientDataSetFeedsEDt.IsNull
4124
      then
4125
        ClientDataSetFeedsEDt.Value := ClientDataSetFeedsEDt.Value / RapMS;
4126
      if not ClientDataSetFeedsEMt.IsNull
4127
      then
4128
        ClientDataSetFeedsEMt.Value := ClientDataSetFeedsEMt.Value / RapMS;
4129
      if not ClientDataSetFeedsENt.IsNull
4130
      then
4131
        ClientDataSetFeedsENt.Value := ClientDataSetFeedsENt.Value / RapMS;
4132
      // Digestibilit? f?cale de l'azote
4133
      if not ClientDataSetFeedsdNc.IsNull
4134
      then
4135
        ClientDataSetFeedsdNc.Value := ClientDataSetFeedsdNc.Value / RapMS;
4136
      if not ClientDataSetFeedsdNt.IsNull
4137
      then
4138
        ClientDataSetFeedsdNt.Value := ClientDataSetFeedsdNt.Value / RapMS;
4139
      // Acides amin?s
4140
      if not ClientDataSetFeedsLys.IsNull
4141
      then
4142
      begin
4143
        ClientDataSetFeedsLys.Value := ClientDataSetFeedsLys.Value / RapMS;
4144
        ClientDataSetFeedsLysd.Value := ClientDataSetFeedsLysd.Value / RapMS;
4145
      end;
4146
      if not ClientDataSetFeedsThr.IsNull
4147
      then
4148
      begin
4149
        ClientDataSetFeedsThr.Value := ClientDataSetFeedsThr.Value / RapMS;
4150
        ClientDataSetFeedsThrd.Value := ClientDataSetFeedsThrd.Value / RapMS;
4151
      end;
4152
      if not ClientDataSetFeedsMet.IsNull
4153
      then
4154
      begin
4155
        ClientDataSetFeedsMet.Value := ClientDataSetFeedsMet.Value / RapMS;
4156
        ClientDataSetFeedsMetd.Value := ClientDataSetFeedsMetd.Value / RapMS;
4157
      end;
4158
      if not ClientDataSetFeedsCys.IsNull
4159
      then
4160
      begin
4161
        ClientDataSetFeedsCys.Value := ClientDataSetFeedsCys.Value / RapMS;
4162
        ClientDataSetFeedsCysd.Value := ClientDataSetFeedsCysd.Value / RapMS;
4163
      end;
4164
      if not ClientDataSetFeedsMetCys.IsNull
4165
      then
4166
      begin
4167
        ClientDataSetFeedsMetCys.Value := ClientDataSetFeedsMetCys.Value / RapMS;
4168
        ClientDataSetFeedsMetCysd.Value := ClientDataSetFeedsMetCysd.Value / RapMS;
4169
      end;
4170
      if not ClientDataSetFeedsTrp.IsNull
4171
      then
4172
      begin
4173
        ClientDataSetFeedsTrp.Value := ClientDataSetFeedsTrp.Value / RapMS;
4174
        ClientDataSetFeedsTrpd.Value := ClientDataSetFeedsTrpd.Value / RapMS;
4175
      end;
4176
      if not ClientDataSetFeedsIle.IsNull
4177
      then
4178
      begin
4179
        ClientDataSetFeedsIle.Value := ClientDataSetFeedsIle.Value / RapMS;
4180
        ClientDataSetFeedsIled.Value := ClientDataSetFeedsIled.Value / RapMS;
4181
      end;
4182
      if not ClientDataSetFeedsVal.IsNull
4183
      then
4184
      begin
4185
        ClientDataSetFeedsVal.Value := ClientDataSetFeedsVal.Value / RapMS;
4186
        ClientDataSetFeedsVald.Value := ClientDataSetFeedsVald.Value / RapMS;
4187
      end;
4188
      if not ClientDataSetFeedsLeu.IsNull
4189
      then
4190
      begin
4191
        ClientDataSetFeedsLeu.Value := ClientDataSetFeedsLeu.Value / RapMS;
4192
        ClientDataSetFeedsLeud.Value := ClientDataSetFeedsLeud.Value / RapMS;
4193
      end;
4194
      if not ClientDataSetFeedsPhe.IsNull
4195
      then
4196
      begin
4197
        ClientDataSetFeedsPhe.Value := ClientDataSetFeedsPhe.Value / RapMS;
4198
        ClientDataSetFeedsPhed.Value := ClientDataSetFeedsPhed.Value / RapMS;
4199
      end;
4200
      if not ClientDataSetFeedsTyr.IsNull
4201
      then
4202
      begin
4203
        ClientDataSetFeedsTyr.Value := ClientDataSetFeedsTyr.Value / RapMS;
4204
        ClientDataSetFeedsTyrd.Value := ClientDataSetFeedsTyrd.Value / RapMS;
4205
      end;
4206
      if not ClientDataSetFeedsPheTyr.IsNull
4207
      then
4208
      begin
4209
        ClientDataSetFeedsPheTyr.Value := ClientDataSetFeedsPheTyr.Value / RapMS;
4210
        ClientDataSetFeedsPheTyrd.Value := ClientDataSetFeedsPheTyrd.Value / RapMS;
4211
      end;
4212
      if not ClientDataSetFeedsHis.IsNull
4213
      then
4214
      begin
4215
        ClientDataSetFeedsHis.Value := ClientDataSetFeedsHis.Value / RapMS;
4216
        ClientDataSetFeedsHisd.Value := ClientDataSetFeedsHisd.Value / RapMS;
4217
      end;
4218
      if not ClientDataSetFeedsArg.IsNull
4219
      then
4220
      begin
4221
        ClientDataSetFeedsArg.Value := ClientDataSetFeedsArg.Value / RapMS;
4222
        ClientDataSetFeedsArgd.Value := ClientDataSetFeedsArgd.Value / RapMS;
4223
      end;
4224
      if not ClientDataSetFeedsAla.IsNull
4225
      then
4226
      begin
4227
        ClientDataSetFeedsAla.Value := ClientDataSetFeedsAla.Value / RapMS;
4228
        ClientDataSetFeedsAlad.Value := ClientDataSetFeedsAlad.Value / RapMS;
4229
      end;
4230
      if not ClientDataSetFeedsAsp.IsNull
4231
      then
4232
      begin
4233
        ClientDataSetFeedsAsp.Value := ClientDataSetFeedsAsp.Value / RapMS;
4234
        ClientDataSetFeedsAspd.Value := ClientDataSetFeedsAspd.Value / RapMS;
4235
      end;
4236
      if not ClientDataSetFeedsGlu.IsNull
4237
      then
4238
      begin
4239
        ClientDataSetFeedsGlu.Value := ClientDataSetFeedsGlu.Value / RapMS;
4240
        ClientDataSetFeedsGlud.Value := ClientDataSetFeedsGlud.Value / RapMS;
4241
      end;
4242
      if not ClientDataSetFeedsGly.IsNull
4243
      then
4244
      begin
4245
        ClientDataSetFeedsGly.Value := ClientDataSetFeedsGly.Value / RapMS;
4246
        ClientDataSetFeedsGlyd.Value := ClientDataSetFeedsGlyd.Value / RapMS;
4247
      end;
4248
      if not ClientDataSetFeedsSer.IsNull
4249
      then
4250
      begin
4251
        ClientDataSetFeedsSer.Value := ClientDataSetFeedsSer.Value / RapMS;
4252
        ClientDataSetFeedsSerd.Value := ClientDataSetFeedsSerd.Value / RapMS;
4253
      end;
4254
      if not ClientDataSetFeedsPro.IsNull
4255
      then
4256
      begin
4257
        ClientDataSetFeedsPro.Value := ClientDataSetFeedsPro.Value / RapMS;
4258
        ClientDataSetFeedsProd.Value := ClientDataSetFeedsProd.Value / RapMS;
4259
      end;
4260
      // Min?raux
4261
      if not ClientDataSetFeedsCa.IsNull
4262
      then
4263
        ClientDataSetFeedsCa.Value := ClientDataSetFeedsCa.Value / RapMS;
4264
      if not ClientDataSetFeedsP.IsNull
4265
      then
4266
        ClientDataSetFeedsP.Value := ClientDataSetFeedsP.Value / RapMS;
4267
      if not ClientDataSetFeedsNa.IsNull
4268
      then
4269
        ClientDataSetFeedsNa.Value := ClientDataSetFeedsNa.Value / RapMS;
4270
      if not ClientDataSetFeedsK.IsNull
4271
      then
4272
        ClientDataSetFeedsK.Value := ClientDataSetFeedsK.Value / RapMS;
4273
      if not ClientDataSetFeedsCl.IsNull
4274
      then
4275
        ClientDataSetFeedsCl.Value := ClientDataSetFeedsCl.Value / RapMS;
4276
      if not ClientDataSetFeedsEB.IsNull
4277
      then
4278
        ClientDataSetFeedsEB.Value := ClientDataSetFeedsEB.Value / RapMS;
4279
      if not ClientDataSetFeedsPd.IsNull
4280
      then
4281
        ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value / RapMS;
4282
    end;
4283
  end;
4284
  if ClientDataSetFeedsNa.IsNull or ClientDataSetFeedsK.IsNull or ClientDataSetFeedsCl.IsNull
4285
  then
4286
    ClientDataSetFeedsBE.Clear
4287
  else
4288
    ClientDataSetFeedsBE.Value := CalcBilanElectrolytique(InputMinerals(ClientDataSetFeedsNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetFeedsK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetFeedsCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals));
4289
  // Rapports
4290
  if ClientDataSetFeedsEDc.IsNull or ClientDataSetFeedsEB.IsNull or (ClientDataSetFeedsEB.Value = 0)
4291
  then
4292
    ClientDataSetFeedsdEc.Clear
4293
  else
4294
    ClientDataSetFeedsdEc.Value := ClientDataSetFeedsEDc.Value / ClientDataSetFeedsEB.Value * 100;
4295
  if ClientDataSetFeedsEMc.IsNull or ClientDataSetFeedsEDc.IsNull or (ClientDataSetFeedsEDc.Value = 0)
4296
  then
4297
    ClientDataSetFeedsEMc_EDc.Clear
4298
  else
4299
    ClientDataSetFeedsEMc_EDc.Value := ClientDataSetFeedsEMc.Value / ClientDataSetFeedsEDc.Value * 100;
4300
  if ClientDataSetFeedsENc.IsNull or ClientDataSetFeedsEMc.IsNull or (ClientDataSetFeedsEMc.Value = 0)
4301
  then
4302
    ClientDataSetFeedsENc_EMc.Clear
4303
  else
4304
    ClientDataSetFeedsENc_EMc.Value := ClientDataSetFeedsENc.Value / ClientDataSetFeedsEMc.Value * 100;
4305
  if ClientDataSetFeedsEDt.IsNull or ClientDataSetFeedsEB.IsNull or (ClientDataSetFeedsEB.Value = 0)
4306
  then
4307
    ClientDataSetFeedsdEt.Clear
4308
  else
4309
    ClientDataSetFeedsdEt.Value := ClientDataSetFeedsEDt.Value / ClientDataSetFeedsEB.Value * 100;
4310
  if ClientDataSetFeedsEMt.IsNull or ClientDataSetFeedsEDt.IsNull or (ClientDataSetFeedsEDt.Value = 0)
4311
  then
4312
    ClientDataSetFeedsEMt_EDt.Clear
4313
  else
4314
    ClientDataSetFeedsEMt_EDt.Value := ClientDataSetFeedsEMt.Value / ClientDataSetFeedsEDt.Value * 100;
4315
  if ClientDataSetFeedsENt.IsNull or ClientDataSetFeedsEMt.IsNull or (ClientDataSetFeedsEMt.Value = 0)
4316
  then
4317
    ClientDataSetFeedsENt_EMt.Clear
4318
  else
4319
    ClientDataSetFeedsENt_EMt.Value := ClientDataSetFeedsENt.Value / ClientDataSetFeedsEMt.Value * 100;
4320
  if ClientDataSetFeedsBonusC.Value <> 0
4321
  then // Prise en compte du bonus (porc croissance)
4322
  begin
4323
    if not ClientDataSetFeedsdEc.IsNull
4324
    then
4325
      ClientDataSetFeedsdEc.Value := ClientDataSetFeedsdEc.Value + ClientDataSetFeedsBonusC.Value;
4326
    if not ClientDataSetFeedsEB.IsNull and not ClientDataSetFeedsdEc.IsNull
4327
    then
4328
      ClientDataSetFeedsEDc.Value := ClientDataSetFeedsEB.Value * ClientDataSetFeedsdEc.Value / 100;
4329
    if not ClientDataSetFeedsEDc.IsNull and not ClientDataSetFeedsEMc_EDc.IsNull
4330
    then
4331
      ClientDataSetFeedsEMc.Value := ClientDataSetFeedsEDc.Value * ClientDataSetFeedsEMc_EDc.Value / 100;
4332
    if not ClientDataSetFeedsEMc.IsNull and not ClientDataSetFeedsENc_EMc.IsNull
4333
    then
4334
      ClientDataSetFeedsENc.Value := ClientDataSetFeedsEMc.Value * ClientDataSetFeedsENc_EMc.Value / 100;
4335
  end;
4336
  if ClientDataSetFeedsBonusT.Value <> 0
4337
  then // Prise en compte du bonus (porce adulte)
4338
  begin
4339
    if not ClientDataSetFeedsdEt.IsNull
4340
    then
4341
      ClientDataSetFeedsdEt.Value := ClientDataSetFeedsdEt.Value + ClientDataSetFeedsBonusT.Value;
4342
    if not ClientDataSetFeedsEB.IsNull and not ClientDataSetFeedsdEt.IsNull
4343
    then
4344
      ClientDataSetFeedsEDt.Value := ClientDataSetFeedsEB.Value * ClientDataSetFeedsdEt.Value / 100;
4345
    if not ClientDataSetFeedsEDt.IsNull and not ClientDataSetFeedsEMt_EDt.IsNull
4346
    then
4347
      ClientDataSetFeedsEMt.Value := ClientDataSetFeedsEDt.Value * ClientDataSetFeedsEMt_EDt.Value / 100;
4348
    if not ClientDataSetFeedsEMt.IsNull and not ClientDataSetFeedsENt_EMt.IsNull
4349
    then
4350
      ClientDataSetFeedsENt.Value := ClientDataSetFeedsEMt.Value * ClientDataSetFeedsENt_EMt.Value / 100;
4351
  end;
4352
  if ClientDataSetFeedsEDt.IsNull or ClientDataSetFeedsEDc.IsNull or (ClientDataSetFeedsEDc.Value = 0)
4353
  then
4354
    ClientDataSetFeedsEDt_EDc.Clear
4355
  else
4356
    ClientDataSetFeedsEDt_EDc.Value := ClientDataSetFeedsEDt.Value / ClientDataSetFeedsEDc.Value * 100;
4357
  if ClientDataSetFeedsEMt.IsNull or ClientDataSetFeedsEMc.IsNull or (ClientDataSetFeedsEMc.Value = 0)
4358
  then
4359
    ClientDataSetFeedsEMt_EMc.Clear
4360
  else
4361
    ClientDataSetFeedsEMt_EMc.Value := ClientDataSetFeedsEMt.Value / ClientDataSetFeedsEMc.Value * 100;
4362
  if ClientDataSetFeedsENt.IsNull or ClientDataSetFeedsENc.IsNull or (ClientDataSetFeedsENc.Value = 0)
4363
  then
4364
    ClientDataSetFeedsENt_ENc.Clear
4365
  else
4366
    ClientDataSetFeedsENt_ENc.Value := ClientDataSetFeedsENt.Value / ClientDataSetFeedsENc.Value * 100;
4367
  if not ClientDataSetFeedsdNc.IsNull
4368
  then
4369
    if ClientDataSetFeedsMAT.IsNull or (ClientDataSetFeedsMAT.Value = 0)
4370
    then
4371
      ClientDataSetFeedsdNc.Clear
4372
    else // dN = MATd / MAT
4373
      ClientDataSetFeedsdNc.Value := ClientDataSetFeedsdNc.Value / ClientDataSetFeedsMAT.Value * 100;
4374
  if not ClientDataSetFeedsdNt.IsNull
4375
  then
4376
    if ClientDataSetFeedsMAT.IsNull or (ClientDataSetFeedsMAT.Value = 0)
4377
    then
4378
      ClientDataSetFeedsdNt.Clear
4379
    else // dN = MATd / MAT
4380
      ClientDataSetFeedsdNt.Value := ClientDataSetFeedsdNt.Value / ClientDataSetFeedsMAT.Value * 100;
4381
  if ClientDataSetFeedsLysd.IsNull or ClientDataSetFeedsENc.IsNull or (ClientDataSetFeedsENc.Value = 0)
4382
  then
4383
    ClientDataSetFeedsLysd_ENc.Clear
4384
  else
4385
    if FormOptions.Energy = 0
4386
    then // g/MJ
4387
      if FormOptions.AA = 0
4388
      then // % (conversion)
4389
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value
4390
      else // g/kg
4391
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENc.Value
4392
    else // g/1000kcal
4393
      if FormOptions.AA = 0
4394
      then // % (conversion)
4395
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value * 1000
4396
      else // g/kg
4397
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENc.Value * 1000;
4398
  if ClientDataSetFeedsLysd.IsNull or ClientDataSetFeedsENt.IsNull or (ClientDataSetFeedsENt.Value = 0)
4399
  then
4400
    ClientDataSetFeedsLysd_ENt.Clear
4401
  else
4402
    if FormOptions.Energy = 0
4403
    then // g/MJ
4404
      if FormOptions.AA = 0
4405
      then // % (conversion)
4406
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value
4407
      else // g/kg
4408
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENt.Value
4409
    else // g/1000kcal
4410
      if FormOptions.AA = 0
4411
      then // % (conversion)
4412
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value * 1000
4413
      else // g/kg
4414
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENt.Value * 1000;
4415
  if ClientDataSetFeedsCa.IsNull or ClientDataSetFeedsPd.IsNull or (ClientDataSetFeedsPd.Value = 0)
4416
  then
4417
    ClientDataSetFeedsCa_Pd.Clear
4418
  else
4419
    ClientDataSetFeedsCa_Pd.Value := ClientDataSetFeedsCa.Value / ClientDataSetFeedsPd.Value;
4420
  if ClientDataSetFeedsPd.IsNull or ClientDataSetFeedsENc.IsNull or (ClientDataSetFeedsENc.Value = 0)
4421
  then
4422
    ClientDataSetFeedsPd_ENc.Clear
4423
  else
4424
    if FormOptions.Energy = 0
4425
    then // g/MJ
4426
      if FormOptions.Minerals = 0
4427
      then // % (conversion)
4428
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value
4429
      else // g/kg
4430
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENc.Value
4431
    else // g/1000kcal
4432
      if FormOptions.Minerals = 0
4433
      then // % (conversion)
4434
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value * 1000
4435
      else // g/kg
4436
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENc.Value * 1000;
4437
  if ClientDataSetFeedsPd.IsNull or ClientDataSetFeedsENt.IsNull or (ClientDataSetFeedsENt.Value = 0)
4438
  then
4439
    ClientDataSetFeedsPd_ENt.Clear
4440
  else
4441
    if FormOptions.Energy = 0
4442
    then // g/MJ
4443
      if FormOptions.Minerals = 0
4444
      then // % (conversion)
4445
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value
4446
      else // g/kg
4447
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENt.Value
4448
    else // g/1000 kcal
4449
      if FormOptions.Minerals = 0
4450
      then // % (conversion)
4451
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value * 1000
4452
      else // g/kg
4453
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENt.Value * 1000;
4454
  if ClientDataSetFeedsThrd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4455
  then
4456
    ClientDataSetFeedsThrd_Lysd.Clear
4457
  else
4458
    ClientDataSetFeedsThrd_Lysd.Value := ClientDataSetFeedsThrd.Value / ClientDataSetFeedsLysd.Value * 100;
4459
  if ClientDataSetFeedsMetd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4460
  then
4461
    ClientDataSetFeedsMetd_Lysd.Clear
4462
  else
4463
    ClientDataSetFeedsMetd_Lysd.Value := ClientDataSetFeedsMetd.Value / ClientDataSetFeedsLysd.Value * 100;
4464
  if ClientDataSetFeedsCysd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4465
  then
4466
    ClientDataSetFeedsCysd_Lysd.Clear
4467
  else
4468
    ClientDataSetFeedsCysd_Lysd.Value := ClientDataSetFeedsCysd.Value / ClientDataSetFeedsLysd.Value * 100;
4469
  if ClientDataSetFeedsMetCysd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4470
  then
4471
    ClientDataSetFeedsMetCysd_Lysd.Clear
4472
  else
4473
    ClientDataSetFeedsMetCysd_Lysd.Value := ClientDataSetFeedsMetCysd.Value / ClientDataSetFeedsLysd.Value * 100;
4474
  if ClientDataSetFeedsTrpd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4475
  then
4476
    ClientDataSetFeedsTrpd_Lysd.Clear
4477
  else
4478
    ClientDataSetFeedsTrpd_Lysd.Value := ClientDataSetFeedsTrpd.Value / ClientDataSetFeedsLysd.Value * 100;
4479
  if ClientDataSetFeedsIled.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4480
  then
4481
    ClientDataSetFeedsIled_Lysd.Clear
4482
  else
4483
    ClientDataSetFeedsIled_Lysd.Value := ClientDataSetFeedsIled.Value / ClientDataSetFeedsLysd.Value * 100;
4484
  if ClientDataSetFeedsVald.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4485
  then
4486
    ClientDataSetFeedsVald_Lysd.Clear
4487
  else
4488
    ClientDataSetFeedsVald_Lysd.Value := ClientDataSetFeedsVald.Value / ClientDataSetFeedsLysd.Value * 100;
4489
  if ClientDataSetFeedsLeud.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4490
  then
4491
    ClientDataSetFeedsLeud_Lysd.Clear
4492
  else
4493
    ClientDataSetFeedsLeud_Lysd.Value := ClientDataSetFeedsLeud.Value / ClientDataSetFeedsLysd.Value * 100;
4494
  if ClientDataSetFeedsPhed.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4495
  then
4496
    ClientDataSetFeedsPhed_Lysd.Clear
4497
  else
4498
    ClientDataSetFeedsPhed_Lysd.Value := ClientDataSetFeedsPhed.Value / ClientDataSetFeedsLysd.Value * 100;
4499
  if ClientDataSetFeedsTyrd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4500
  then
4501
    ClientDataSetFeedsTyrd_Lysd.Clear
4502
  else
4503
    ClientDataSetFeedsTyrd_Lysd.Value := ClientDataSetFeedsTyrd.Value / ClientDataSetFeedsLysd.Value * 100;
4504
  if ClientDataSetFeedsPheTyrd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4505
  then
4506
    ClientDataSetFeedsPheTyrd_Lysd.Clear
4507
  else
4508
    ClientDataSetFeedsPheTyrd_Lysd.Value := ClientDataSetFeedsPheTyrd.Value / ClientDataSetFeedsLysd.Value * 100;
4509
  if ClientDataSetFeedsHisd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4510
  then
4511
    ClientDataSetFeedsHisd_Lysd.Clear
4512
  else
4513
    ClientDataSetFeedsHisd_Lysd.Value := ClientDataSetFeedsHisd.Value / ClientDataSetFeedsLysd.Value * 100;
4514
  if ClientDataSetFeedsArgd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4515
  then
4516
    ClientDataSetFeedsArgd_Lysd.Clear
4517
  else
4518
    ClientDataSetFeedsArgd_Lysd.Value := ClientDataSetFeedsArgd.Value / ClientDataSetFeedsLysd.Value * 100;
4519
  if ClientDataSetFeedsAlad.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4520
  then
4521
    ClientDataSetFeedsAlad_Lysd.Clear
4522
  else
4523
    ClientDataSetFeedsAlad_Lysd.Value := ClientDataSetFeedsAlad.Value / ClientDataSetFeedsLysd.Value * 100;
4524
  if ClientDataSetFeedsAspd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4525
  then
4526
    ClientDataSetFeedsAspd_Lysd.Clear
4527
  else
4528
    ClientDataSetFeedsAspd_Lysd.Value := ClientDataSetFeedsAspd.Value / ClientDataSetFeedsLysd.Value * 100;
4529
  if ClientDataSetFeedsGlud.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4530
  then
4531
    ClientDataSetFeedsGlud_Lysd.Clear
4532
  else
4533
    ClientDataSetFeedsGlud_Lysd.Value := ClientDataSetFeedsGlud.Value / ClientDataSetFeedsLysd.Value * 100;
4534
  if ClientDataSetFeedsGlyd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4535
  then
4536
    ClientDataSetFeedsGlyd_Lysd.Clear
4537
  else
4538
    ClientDataSetFeedsGlyd_Lysd.Value := ClientDataSetFeedsGlyd.Value / ClientDataSetFeedsLysd.Value * 100;
4539
  if ClientDataSetFeedsSerd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4540
  then
4541
    ClientDataSetFeedsSerd_Lysd.Clear
4542
  else
4543
    ClientDataSetFeedsSerd_Lysd.Value := ClientDataSetFeedsSerd.Value / ClientDataSetFeedsLysd.Value * 100;
4544
  if ClientDataSetFeedsProd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4545
  then
4546
    ClientDataSetFeedsProd_Lysd.Clear
4547
  else
4548
    ClientDataSetFeedsProd_Lysd.Value := ClientDataSetFeedsProd.Value / ClientDataSetFeedsLysd.Value * 100;
4549
end;
4550

    
4551
function TDataModuleDeclaration.CalcBilanElectrolytique(Na, K, Cl: Double): Double;
4552
begin
4553
  Result := (Na / 23 + K / 39 - Cl / 35.5) * 1000000;
4554
  if FormOptions.Expression = 0
4555
  then // sur frais
4556
    Result := Result * RapMS;
4557
end;
4558

    
4559
function TDataModuleDeclaration.InputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
4560
begin
4561
  if ProximalUnit = 0
4562
  then // %
4563
    Result := Value / 100
4564
  else // g/kg
4565
    Result := Value / 1000;
4566
  if ExpressionMode = 0
4567
  then // sur frais
4568
    Result := Result / MS;
4569
end;
4570

    
4571
function TDataModuleDeclaration.InputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
4572
begin
4573
  if EnergyUnit = 0
4574
  then // MJ/kg
4575
    Result := Value
4576
  else // kcal/kg
4577
    Result := Value * CALORIE / 1000;
4578
  if ExpressionMode = 0
4579
  then // sur frais
4580
    Result := Result / MS;
4581
end;
4582

    
4583
function TDataModuleDeclaration.InputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
4584
begin
4585
  if AAUnit = 0
4586
  then // %
4587
    Result := Value / MAT / 100
4588
  else // g/kg
4589
    Result := Value / MAT / 1000;
4590
  if ExpressionMode = 0
4591
  then // sur frais
4592
    Result := Result / MS;
4593
end;
4594

    
4595
function TDataModuleDeclaration.InputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
4596
begin
4597
  if MineralsUnit = 0
4598
  then // %
4599
    Result := Value / 100
4600
  else // g/kg
4601
    Result := Value / 1000;
4602
  if ExpressionMode = 0
4603
  then // sur frais
4604
    Result := Result / MS;
4605
end;
4606

    
4607
function TDataModuleDeclaration.InputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
4608
begin
4609
  if IncorporationUnit = 0
4610
  then // %
4611
    Result := Value / 100
4612
  else // g/kg
4613
    Result := Value / 1000;
4614
end;
4615

    
4616
function TDataModuleDeclaration.OutputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
4617
begin
4618
  if ProximalUnit = 0
4619
  then // %
4620
    Result := Value * 100
4621
  else // g/kg
4622
    Result := Value * 1000;
4623
  if ExpressionMode = 0
4624
  then // sur frais
4625
    Result := Result * MS;
4626
end;
4627

    
4628
function TDataModuleDeclaration.OutputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
4629
begin
4630
  if EnergyUnit = 0
4631
  then // MJ/kg
4632
    Result := Value
4633
  else // kcal/kg
4634
    Result := Value / CALORIE * 1000;
4635
  if ExpressionMode = 0
4636
  then // sur frais
4637
    Result := Result * MS;
4638
end;
4639

    
4640
function TDataModuleDeclaration.OutputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
4641
begin
4642
  if AAUnit = 0
4643
  then // %
4644
    Result := Value * MAT * 100
4645
  else // g/kg
4646
    Result := Value * MAT * 1000;
4647
  if ExpressionMode = 0
4648
  then // sur frais
4649
    Result := Result * MS;
4650
end;
4651

    
4652
function TDataModuleDeclaration.OutputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
4653
begin
4654
  if MineralsUnit = 0
4655
  then // %
4656
    Result := Value * 100
4657
  else // g/kg
4658
    Result := Value * 1000;
4659
  if ExpressionMode = 0
4660
  then // sur frais
4661
    Result := Result * MS;
4662
end;
4663

    
4664
function TDataModuleDeclaration.OutputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
4665
begin
4666
  if IncorporationUnit = 0
4667
  then // %
4668
    Result := Value * 100
4669
  else // g/kg
4670
    Result := Value * 1000;
4671
end;
4672

    
4673
function TDataModuleDeclaration.StrTrunc(S: String; Max: Integer): String;
4674
var
4675
  l, r: Integer;
4676
begin
4677
  if ElementToCharLen(S, Length(S)) > Max
4678
  then // Cut string S to Max chars
4679
  begin
4680
    l := Max div 2;
4681
    r := Max - l - 3;
4682
    Result := AnsiLeftStr(S, l) + '...' + AnsiRightStr(S, r);
4683
  end
4684
  else
4685
    Result := S;
4686
end;
4687

    
4688
end.