Statistiques
| Révision:

root / UnitPredictionDetail.pas @ 11

Historique | Voir | Annoter | Télécharger (49,165 ko)

1
unit UnitPredictionDetail;
2

    
3
{$WARN SYMBOL_PLATFORM OFF}
4

    
5
interface
6

    
7
uses
8
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
9
  Dialogs, StdCtrls, ExtCtrls, DB, DBCtrls, Mask, JvEdit, JvExStdCtrls,
10
  JvValidateEdit, JvCsvData, RpSystem, RpRender, RpRenderPDF, RpDefine, RpRave,
11
  RvClass, RvCsStd, RpBase, gnugettext, ActnList, ImgList, JvButton, JvCtrls,
12
  XMLIntf, XMLDoc, RpDevice;
13

    
14
type
15
  TFormPredictionDetail = class(TForm)
16
    RvProjectReport: TRvProject;
17
    RvSystemReport: TRvSystem;
18
    SaveDialogExport: TSaveDialog;
19
    PanelMain: TPanel;
20
    PanelButtons: TPanel;
21
    LabelName: TLabel;
22
    LabelMS: TLabel;
23
    EditName: TEdit;
24
    EditMS: TMemo;
25
    GroupBoxAzote: TGroupBox;
26
    LabelCrois3: TLabel;
27
    LabelTruie3: TLabel;
28
    LabeldN: TLabel;
29
    EditdNc: TMemo;
30
    EditdNt: TMemo;
31
    GroupBoxEnergy: TGroupBox;
32
    LabelEB: TLabel;
33
    LabelED: TLabel;
34
    LabelEM: TLabel;
35
    LabelEN: TLabel;
36
    LabelCrois1: TLabel;
37
    LabelTruie1: TLabel;
38
    LabelRatio: TLabel;
39
    EditEBc: TMemo;
40
    EditEBt: TMemo;
41
    EditEDc: TMemo;
42
    EditEDt: TMemo;
43
    EditEMc: TMemo;
44
    EditEMt: TMemo;
45
    EditENc: TMemo;
46
    EditENt: TMemo;
47
    EditEMt_EMc: TMemo;
48
    EditENt_ENc: TMemo;
49
    EditEBt_EBc: TMemo;
50
    EditEDt_EDc: TMemo;
51
    GroupBoxEnergyUtilization: TGroupBox;
52
    LabeldE: TLabel;
53
    LabelEM_ED: TLabel;
54
    LabelEN_EM: TLabel;
55
    LabelCrois2: TLabel;
56
    LabelTruie2: TLabel;
57
    LabelBonus: TLabel;
58
    EditdEc: TMemo;
59
    EditdEt: TMemo;
60
    EditEMc_EDc: TMemo;
61
    EditEMt_EDt: TMemo;
62
    EditENc_EMc: TMemo;
63
    EditENt_EMt: TMemo;
64
    EditBonusC: TMemo;
65
    EditBonusT: TMemo;
66
    GroupBoxProximal: TGroupBox;
67
    LabelMAT: TLabel;
68
    LabelCB: TLabel;
69
    LabelMG: TLabel;
70
    LabelMM: TLabel;
71
    LabelNDF: TLabel;
72
    LabelADF: TLabel;
73
    LabelAmidon: TLabel;
74
    LabelSucres: TLabel;
75
    LabelMOdv: TLabel;
76
    EditMAT: TMemo;
77
    EditCB: TMemo;
78
    EditMG: TMemo;
79
    EditMM: TMemo;
80
    EditNDF: TMemo;
81
    EditADF: TMemo;
82
    EditAmidon: TMemo;
83
    EditSucres: TMemo;
84
    EditMOdv: TMemo;
85
    ImageListIcons: TImageList;
86
    ActionListButtons: TActionList;
87
    ActionPrint: TAction;
88
    ActionXML: TAction;
89
    ActionHelp: TAction;
90
    ActionClose: TAction;
91
    JvImgBtnClose: TJvImgBtn;
92
    JvImgBtnHelp: TJvImgBtn;
93
    JvImgBtnXML: TJvImgBtn;
94
    JvImgBtnPrint: TJvImgBtn;
95
    procedure FormCreate(Sender: TObject);
96
    procedure FormShow(Sender: TObject);
97
    procedure ActionPrintExecute(Sender: TObject);
98
    procedure ActionXMLExecute(Sender: TObject);
99
    procedure ActionHelpExecute(Sender: TObject);
100
    procedure ActionCloseExecute(Sender: TObject);
101
  private
102
    { D?clarations priv?es }
103
    MS, MM, MAT, MG, CB, NDF, ADF, Amidon, Sucres, dMOv: Double;
104
    EB, dEc, BonusC, EDc, EMc, ENc, dEt, BonusT, EDt, EMt, ENt, dNc, dNt: Double;
105
    procedure BuildReport;
106
  public
107
    { D?clarations publiques }
108
  end;
109

    
110
var
111
  FormPredictionDetail: TFormPredictionDetail;
112

    
113
implementation
114

    
115
uses
116
  UnitDeclaration, UnitOptions, UnitPredictionCreate;
117

    
118
{$R *.dfm}
119

    
120
procedure TFormPredictionDetail.ActionCloseExecute(Sender: TObject);
121
begin
122
  ModalResult := mrClose;
123
end;
124

    
125
procedure TFormPredictionDetail.ActionXMLExecute(Sender: TObject);
126
var
127
  USFormatSettings: TFormatSettings;
128
  XMLDoc: IXMLDocument;
129
  Workbook, Worksheet, Table, Row: IXMLNode;
130

    
131
  procedure CellData(Row: IXMLNode; Value, Format: string);
132
  var
133
    Cell, Data: IXMLNode;
134
  begin
135
    Cell := Row.AddChild('Cell');
136
    Data := Cell.AddChild('Data');
137
    Data.Attributes['ss:Type'] := Format;
138
    Data.Text := Value;
139
  end;
140

    
141
begin
142
  if SaveDialogExport.Execute
143
  then
144
  begin
145
    GetLocaleFormatSettings(1033, USFormatSettings);
146
    XMLDoc := TXMLDocument.Create(nil);
147
    try
148
      XMLDoc.XML.Clear;
149
      XMLDoc.XML.Add('<?xml version="1.0" encoding="UTF-8" ?>');
150
      XMLDoc.XML.Add('<?mso-application progid="Excel.Sheet"?>');
151
      XMLDoc.XML.Add('<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet">');
152
      XMLDoc.XML.Add('</Workbook>');
153
      XMLDoc.Active := True;
154
      Workbook := XMLDoc.DocumentElement;
155
      Workbook.DeclareNamespace('o', 'urn:schemas-microsoft-com:office:office');
156
      Workbook.DeclareNamespace('x', 'urn:schemas-microsoft-com:office:excel');
157
      Workbook.DeclareNamespace('ss', 'urn:schemas-microsoft-com:office:spreadsheet');
158
      Workbook.DeclareNamespace('html', 'http://www.w3.org/TR/REC-html40');
159
      Worksheet := Workbook.AddChild('Worksheet');
160
      Worksheet.SetAttributeNS('ss:Name', Workbook.FindNamespaceURI('ss'), Caption);
161
      Table := Worksheet.AddChild('Table');
162
      // Titre
163
      Row := Table.AddChild('Row');
164
      CellData(Row, _('Label'), 'String');
165
      CellData(Row, _('Value'), 'String');
166
      CellData(Row, _('Unit'), 'String');
167
      // Donn?es
168
      Row := Table.AddChild('Row');
169
      CellData(Row, LabelName.Caption, 'String');
170
      CellData(Row, EditName.Text, 'String');
171
      // Analyse proximale
172
      Row := Table.AddChild('Row');
173
      CellData(Row, LabelMS.Caption, 'String');
174
      CellData(Row, FloatToStrF(MS, ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number');
175
      if FormOptions.Expression = 0
176
      then // sur frais
177
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
178
      else // sur mati?re s?che
179
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
180
      Row := Table.AddChild('Row');
181
      CellData(Row, LabelMM.Caption, 'String');
182
      if EditMM.Text <> ''
183
      then
184
        with DataModuleDeclaration do
185
          CellData(Row, FloatToStrF(OutputProximal(MM, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
186
      else
187
        CellData(Row, '', 'String');
188
      if FormOptions.Expression = 0
189
      then // sur frais
190
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
191
      else // sur mati?re s?che
192
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
193
      Row := Table.AddChild('Row');
194
      CellData(Row, LabelMAT.Caption, 'String');
195
      if EditMAT.Text <> ''
196
      then
197
        with DataModuleDeclaration do
198
          CellData(Row, FloatToStrF(OutputProximal(MAT, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
199
      else
200
        CellData(Row, '', 'String');
201
      if FormOptions.Expression = 0
202
      then // sur frais
203
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
204
      else // sur mati?re s?che
205
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
206
      Row := Table.AddChild('Row');
207
      CellData(Row, LabelMG.Caption, 'String');
208
      if EditMG.Text <> ''
209
      then
210
        with DataModuleDeclaration do
211
          CellData(Row, FloatToStrF(OutputProximal(MG, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
212
      else
213
        CellData(Row, '', 'String');
214
      if FormOptions.Expression = 0
215
      then // sur frais
216
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
217
      else // sur mati?re s?che
218
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
219
      Row := Table.AddChild('Row');
220
      CellData(Row, LabelCB.Caption, 'String');
221
      if EditCB.Text <> ''
222
      then
223
        with DataModuleDeclaration do
224
          CellData(Row, FloatToStrF(OutputProximal(CB, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
225
      else
226
        CellData(Row, '', 'String');
227
      if FormOptions.Expression = 0
228
      then // sur frais
229
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
230
      else // sur mati?re s?che
231
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
232
      Row := Table.AddChild('Row');
233
      CellData(Row, LabelNDF.Caption, 'String');
234
      if EditNDF.Text <> ''
235
      then
236
        with DataModuleDeclaration do
237
          CellData(Row, FloatToStrF(OutputProximal(NDF, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
238
      else
239
        CellData(Row, '', 'String');
240
      if FormOptions.Expression = 0
241
      then // sur frais
242
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
243
      else // sur mati?re s?che
244
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
245
      Row := Table.AddChild('Row');
246
      CellData(Row, LabelADF.Caption, 'String');
247
      if EditADF.Text <> ''
248
      then
249
        with DataModuleDeclaration do
250
          CellData(Row, FloatToStrF(OutputProximal(ADF, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
251
      else
252
        CellData(Row, '', 'String');
253
      if FormOptions.Expression = 0
254
      then // sur frais
255
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
256
      else // sur mati?re s?che
257
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
258
      Row := Table.AddChild('Row');
259
      CellData(Row, LabelAmidon.Caption, 'String');
260
      if EditAmidon.Text <> ''
261
      then
262
        with DataModuleDeclaration do
263
          CellData(Row, FloatToStrF(OutputProximal(Amidon, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
264
      else
265
        CellData(Row, '', 'String');
266
      if FormOptions.Expression = 0
267
      then // sur frais
268
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
269
      else // sur mati?re s?che
270
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
271
      Row := Table.AddChild('Row');
272
      CellData(Row, LabelSucres.Caption, 'String');
273
      if EditSucres.Text <> ''
274
      then
275
        with DataModuleDeclaration do
276
          CellData(Row, FloatToStrF(OutputProximal(Sucres, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
277
      else
278
        CellData(Row, '', 'String');
279
      if FormOptions.Expression = 0
280
      then // sur frais
281
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
282
      else // sur mati?re s?che
283
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
284
      Row := Table.AddChild('Row');
285
      CellData(Row, LabelMOdv.Hint, 'String');
286
      if EditMOdv.Text <> ''
287
      then
288
        with DataModuleDeclaration do
289
          CellData(Row, FloatToStrF(OutputProximal(dMOv * (1 - MM), RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
290
      else
291
        CellData(Row, '', 'String');
292
      if FormOptions.Expression = 0
293
      then // sur frais
294
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
295
      else // sur mati?re s?che
296
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
297
      // Energie
298
      Row := Table.AddChild('Row');
299
      CellData(Row, LabelEB.Caption, 'String');
300
      if EditEBc.Text <> ''
301
      then
302
        with DataModuleDeclaration do
303
          CellData(Row, FloatToStrF(OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
304
      else
305
        CellData(Row, '', 'String');
306
      if FormOptions.Expression = 0
307
      then // sur frais
308
        CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
309
      else // sur mati?re s?che
310
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
311
      Row := Table.AddChild('Row');
312
      CellData(Row, Format('%s, %s', [LabelED.Caption, _('growing pig')]), 'String');
313
      if EditEDc.Text <> ''
314
      then
315
        with DataModuleDeclaration do
316
          CellData(Row, FloatToStrF(OutputEnergy(EDc, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
317
      else
318
        CellData(Row, '', 'String');
319
      if FormOptions.Expression = 0
320
      then // sur frais
321
        CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
322
      else // sur mati?re s?che
323
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
324
      Row := Table.AddChild('Row');
325
      CellData(Row, Format('%s, %s', [LabelED.Caption, _('adult pig')]), 'String');
326
      if EditEDt.Text <> ''
327
      then
328
        with DataModuleDeclaration do
329
          CellData(Row, FloatToStrF(OutputEnergy(EDt, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
330
      else
331
        CellData(Row, '', 'String');
332
      if FormOptions.Expression = 0
333
      then // sur frais
334
        CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
335
      else // sur mati?re s?che
336
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
337
      Row := Table.AddChild('Row');
338
      CellData(Row, Format('%s, %s', [LabelED.Caption, _('ratio')]), 'String');
339
      if EditEDt_EDc.Text <> ''
340
      then
341
        with DataModuleDeclaration do
342
          CellData(Row, FloatToStrF(EDt / EDc * 100, ffFixed, 15, 1, USFormatSettings), 'Number')
343
      else
344
        CellData(Row, '', 'String');
345
      CellData(Row, '%', 'String');
346
      Row := Table.AddChild('Row');
347
      CellData(Row, Format('%s, %s', [LabelEM.Caption, _('growing pig')]), 'String');
348
      if EditEMc.Text <> ''
349
      then
350
        with DataModuleDeclaration do
351
          CellData(Row, FloatToStrF(OutputEnergy(EMc, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
352
      else
353
        CellData(Row, '', 'String');
354
      if FormOptions.Expression = 0
355
      then // sur frais
356
        CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
357
      else // sur mati?re s?che
358
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
359
      Row := Table.AddChild('Row');
360
      CellData(Row, Format('%s, %s', [LabelEM.Caption, _('adult pig')]), 'String');
361
      if EditEMt.Text <> ''
362
      then
363
        with DataModuleDeclaration do
364
          CellData(Row, FloatToStrF(OutputEnergy(EMt, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
365
      else
366
        CellData(Row, '', 'String');
367
      if FormOptions.Expression = 0
368
      then // sur frais
369
        CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
370
      else // sur mati?re s?che
371
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
372
      Row := Table.AddChild('Row');
373
      CellData(Row, Format('%s, %s', [LabelEM.Caption, _('ratio')]), 'String');
374
      if EditEMt_EMc.Text <> ''
375
      then
376
        with DataModuleDeclaration do
377
          CellData(Row, FloatToStrF(EMt / EMc * 100, ffFixed, 15, 1, USFormatSettings), 'Number')
378
      else
379
        CellData(Row, '', 'String');
380
      CellData(Row, '%', 'String');
381
      Row := Table.AddChild('Row');
382
      CellData(Row, Format('%s, %s', [LabelEN.Caption, _('growing pig')]), 'String');
383
      if EditENc.Text <> ''
384
      then
385
        with DataModuleDeclaration do
386
          CellData(Row, FloatToStrF(OutputEnergy(ENc, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
387
      else
388
        CellData(Row, '', 'String');
389
      if FormOptions.Expression = 0
390
      then // sur frais
391
        CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
392
      else // sur mati?re s?che
393
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
394
      Row := Table.AddChild('Row');
395
      CellData(Row, Format('%s, %s', [LabelEN.Caption, _('adult pig')]), 'String');
396
      if EditENt.Text <> ''
397
      then
398
        with DataModuleDeclaration do
399
          CellData(Row, FloatToStrF(OutputEnergy(ENt, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
400
      else
401
        CellData(Row, '', 'String');
402
      if FormOptions.Expression = 0
403
      then // sur frais
404
        CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
405
      else // sur mati?re s?che
406
        CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
407
      Row := Table.AddChild('Row');
408
      CellData(Row, Format('%s, %s', [LabelEN.Caption, _('ratio')]), 'String');
409
      if EditENt_ENc.Text <> ''
410
      then
411
        with DataModuleDeclaration do
412
          CellData(Row, FloatToStrF(ENt / ENc * 100, ffFixed, 15, 1, USFormatSettings), 'Number')
413
      else
414
        CellData(Row, '', 'String');
415
      CellData(Row, '%', 'String');
416
      Row := Table.AddChild('Row');
417
      CellData(Row, Format('%s, %s', [LabelBonus.Caption, _('growing pig')]), 'String');
418
      CellData(Row, FloatToStrF(BonusC, ffFixed, 15, 1, USFormatSettings), 'Number');
419
      CellData(Row, '%', 'String');
420
      Row := Table.AddChild('Row');
421
      CellData(Row, Format('%s, %s', [LabelBonus.Caption, _('adult pig')]), 'String');
422
      CellData(Row, FloatToStrF(BonusT, ffFixed, 15, 1, USFormatSettings), 'Number');
423
      CellData(Row, '%', 'String');
424
      Row := Table.AddChild('Row');
425
      CellData(Row, Format('%s, %s', [LabeldE.Caption, _('growing pig')]), 'String');
426
      if EditdEc.Text <> ''
427
      then
428
        with DataModuleDeclaration do
429
          CellData(Row, FloatToStrF(dEc + BonusC, ffFixed, 15, 1, USFormatSettings), 'Number')
430
      else
431
        CellData(Row, '', 'String');
432
      CellData(Row, '%', 'String');
433
      Row := Table.AddChild('Row');
434
      CellData(Row, Format('%s, %s', [LabeldE.Caption, _('adult pig')]), 'String');
435
      if EditdEt.Text <> ''
436
      then
437
        with DataModuleDeclaration do
438
          CellData(Row, FloatToStrF(dEt + BonusT, ffFixed, 15, 1, USFormatSettings), 'Number')
439
      else
440
        CellData(Row, '', 'String');
441
      CellData(Row, '%', 'String');
442
      Row := Table.AddChild('Row');
443
      CellData(Row, Format('%s, %s', [LabelEM_ED.Caption, _('growing pig')]), 'String');
444
      if EditEMc_EDc.Text <> ''
445
      then
446
        with DataModuleDeclaration do
447
          CellData(Row, FloatToStrF(EMc / EDc * 100, ffFixed, 15, 1, USFormatSettings), 'Number')
448
      else
449
        CellData(Row, '', 'String');
450
      CellData(Row, '%', 'String');
451
      Row := Table.AddChild('Row');
452
      CellData(Row, Format('%s, %s', [LabelEM_ED.Caption, _('adult pig')]), 'String');
453
      if EditEMt_EDt.Text <> ''
454
      then
455
        with DataModuleDeclaration do
456
          CellData(Row, FloatToStrF(EMt / EDt * 100, ffFixed, 15, 1, USFormatSettings), 'Number')
457
      else
458
        CellData(Row, '', 'String');
459
      CellData(Row, '%', 'String');
460
      Row := Table.AddChild('Row');
461
      CellData(Row, Format('%s, %s', [LabelEN_EM.Caption, _('growing pig')]), 'String');
462
      if EditENc_EMc.Text <> ''
463
      then
464
        with DataModuleDeclaration do
465
          CellData(Row, FloatToStrF(ENc / EMc * 100, ffFixed, 15, 1, USFormatSettings), 'Number')
466
      else
467
        CellData(Row, '', 'String');
468
      CellData(Row, '%', 'String');
469
      Row := Table.AddChild('Row');
470
      CellData(Row, Format('%s, %s', [LabelEN_EM.Caption, _('adult pig')]), 'String');
471
      if EditENt_EMt.Text <> ''
472
      then
473
        with DataModuleDeclaration do
474
          CellData(Row, FloatToStrF(ENt / EMt * 100, ffFixed, 15, 1, USFormatSettings), 'Number')
475
      else
476
        CellData(Row, '', 'String');
477
      CellData(Row, '%', 'String');
478
      // Digestibilit? f?cale de l'azote
479
      Row := Table.AddChild('Row');
480
      CellData(Row, Format('%s, %s', [LabeldN.Caption, _('growing pig')]), 'String');
481
      if EditdNc.Text <> ''
482
      then
483
        with DataModuleDeclaration do
484
          CellData(Row, FloatToStrF(dNc, ffFixed, 15, 1, USFormatSettings), 'Number')
485
      else
486
        CellData(Row, '', 'String');
487
      CellData(Row, '%', 'String');
488
      Row := Table.AddChild('Row');
489
      CellData(Row, Format('%s, %s', [LabeldN.Caption, _('adult pig')]), 'String');
490
      if EditdNt.Text <> ''
491
      then
492
        with DataModuleDeclaration do
493
          CellData(Row, FloatToStrF(dNt, ffFixed, 15, 1, USFormatSettings), 'Number')
494
      else
495
        CellData(Row, '', 'String');
496
      CellData(Row, '%', 'String');
497
      XMLDoc.SaveToFile(SaveDialogExport.FileName);
498
      XmlDoc.Active := False;
499
    finally
500
      XMLDoc := nil;
501
    end;
502
  end;
503
end;
504

    
505
procedure TFormPredictionDetail.ActionHelpExecute(Sender: TObject);
506
begin
507
  Application.HelpContext(HelpContext);
508
end;
509

    
510
procedure TFormPredictionDetail.ActionPrintExecute(Sender: TObject);
511
begin
512
  if RpDev.PrinterSetupDialog
513
  then
514
  begin
515
    RvSystemReport.DoNativeOutput := false;
516
    RvSystemReport.DefaultDest := rdPrinter;
517
    RvSystemReport.RenderObject := nil;
518
    RvSystemReport.OutputFileName := '';
519
    RvProjectReport.Open;
520
    BuildReport;
521
    RvProjectReport.Execute;
522
    RvProjectReport.Close;
523
  end;
524
end;
525

    
526
procedure TFormPredictionDetail.BuildReport;
527
var
528
  i: Integer;
529
  Page: TRavePage;
530
begin
531
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportPrediction.PagePrediction', nil) as TRavePage;
532
  for i := 0 to Page.ComponentCount - 1 do
533
    if Page.Components[i].ClassNameIs('TRaveText')
534
    then // Traduire
535
    begin
536
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
537
      then
538
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
539
      TranslateComponent(Page.Components[i]);
540
      if (Page.Components[i] as TRaveText).Name = 'DataTextName'
541
      then
542
        (Page.Components[i] as TRaveText).Text := EditName.Text;
543
      if (Page.Components[i] as TRaveText).Name = 'TextMS'
544
      then
545
        with FormOptions do
546
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, ComboBoxProximal.Items[Proximal]]);
547
      if (Page.Components[i] as TRaveText).Name = 'TextUnitProximal'
548
      then
549
        with FormOptions do
550
          if Expression = 0
551
          then // sur frais
552
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxProximal.Items[Proximal]])
553
          else // sur mati?re s?che
554
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxProximal.Items[Proximal], _('DM')]);
555
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyC'
556
      then
557
        with FormOptions do
558
          if Expression = 0
559
          then // sur frais
560
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxEnergy.Items[Energy]])
561
          else // sur mati?re s?che
562
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxEnergy.Items[Energy], _('DM')]);
563
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyT'
564
      then
565
        with FormOptions do
566
          if Expression = 0
567
          then // sur frais
568
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxEnergy.Items[Energy]])
569
          else // sur mati?re s?che
570
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxEnergy.Items[Energy], _('DM')]);
571
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyRatio'
572
      then
573
        (Page.Components[i] as TRaveText).Text := '(%)';
574
      if (Page.Components[i] as TRaveText).Name = 'TextBonus'
575
      then
576
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
577
      if (Page.Components[i] as TRaveText).Name = 'TextdE'
578
      then
579
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
580
      if (Page.Components[i] as TRaveText).Name = 'TextME_DE'
581
      then
582
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
583
      if (Page.Components[i] as TRaveText).Name = 'TextNE_ME'
584
      then
585
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
586
      if (Page.Components[i] as TRaveText).Name = 'TextdN'
587
      then
588
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
589
      // Affichage des valeurs
590
      if (Page.Components[i] as TRaveText).Name = 'DataTextMS'
591
      then
592
        (Page.Components[i] as TRaveText).Text := EditMS.Text;
593
      if (Page.Components[i] as TRaveText).Name = 'DataTextMM'
594
      then
595
        (Page.Components[i] as TRaveText).Text := EditMM.Text;
596
      if (Page.Components[i] as TRaveText).Name = 'DataTextMAT'
597
      then
598
        (Page.Components[i] as TRaveText).Text := EditMAT.Text;
599
      if (Page.Components[i] as TRaveText).Name = 'DataTextMG'
600
      then
601
        (Page.Components[i] as TRaveText).Text := EditMG.Text;
602
      if (Page.Components[i] as TRaveText).Name = 'DataTextCB'
603
      then
604
        (Page.Components[i] as TRaveText).Text := EditCB.Text;
605
      if (Page.Components[i] as TRaveText).Name = 'DataTextNDF'
606
      then
607
        (Page.Components[i] as TRaveText).Text := EditNDF.Text;
608
      if (Page.Components[i] as TRaveText).Name = 'DataTextADF'
609
      then
610
        (Page.Components[i] as TRaveText).Text := EditADF.Text;
611
      if (Page.Components[i] as TRaveText).Name = 'DataTextAmidon'
612
      then
613
        (Page.Components[i] as TRaveText).Text := EditAmidon.Text;
614
      if (Page.Components[i] as TRaveText).Name = 'DataTextSucres'
615
      then
616
        (Page.Components[i] as TRaveText).Text := EditSucres.Text;
617
      if (Page.Components[i] as TRaveText).Name = 'DataTextMOdv'
618
      then
619
        (Page.Components[i] as TRaveText).Text := EditMOdv.Text;
620
      if (Page.Components[i] as TRaveText).Name = 'DataTextEBc'
621
      then
622
        (Page.Components[i] as TRaveText).Text := EditEBc.Text;
623
      if (Page.Components[i] as TRaveText).Name = 'DataTextEBt'
624
      then
625
        (Page.Components[i] as TRaveText).Text := EditEBt.Text;
626
      if (Page.Components[i] as TRaveText).Name = 'DataTextEBt_EBc'
627
      then
628
        (Page.Components[i] as TRaveText).Text := EditEBt_EBc.Text;
629
      if (Page.Components[i] as TRaveText).Name = 'DataTextEDc'
630
      then
631
        (Page.Components[i] as TRaveText).Text := EditEDc.Text;
632
      if (Page.Components[i] as TRaveText).Name = 'DataTextEDt'
633
      then
634
        (Page.Components[i] as TRaveText).Text := EditEDt.Text;
635
      if (Page.Components[i] as TRaveText).Name = 'DataTextEDt_EDc'
636
      then
637
        (Page.Components[i] as TRaveText).Text := EditEDt_EDc.Text;
638
      if (Page.Components[i] as TRaveText).Name = 'DataTextEMc'
639
      then
640
        (Page.Components[i] as TRaveText).Text := EditEMc.Text;
641
      if (Page.Components[i] as TRaveText).Name = 'DataTextEMt'
642
      then
643
        (Page.Components[i] as TRaveText).Text := EditEMt.Text;
644
      if (Page.Components[i] as TRaveText).Name = 'DataTextEMt_EMc'
645
      then
646
        (Page.Components[i] as TRaveText).Text := EditEMt_EMc.Text;
647
      if (Page.Components[i] as TRaveText).Name = 'DataTextENc'
648
      then
649
        (Page.Components[i] as TRaveText).Text := EditENc.Text;
650
      if (Page.Components[i] as TRaveText).Name = 'DataTextENt'
651
      then
652
        (Page.Components[i] as TRaveText).Text := EditENt.Text;
653
      if (Page.Components[i] as TRaveText).Name = 'DataTextENt_ENc'
654
      then
655
        (Page.Components[i] as TRaveText).Text := EditENt_ENc.Text;
656
      if (Page.Components[i] as TRaveText).Name = 'DataTextBonusC'
657
      then
658
        (Page.Components[i] as TRaveText).Text := EditBonusC.Text;
659
      if (Page.Components[i] as TRaveText).Name = 'DataTextBonusT'
660
      then
661
        (Page.Components[i] as TRaveText).Text := EditBonusT.Text;
662
      if (Page.Components[i] as TRaveText).Name = 'DataTextdEc'
663
      then
664
        (Page.Components[i] as TRaveText).Text := EditdEc.Text;
665
      if (Page.Components[i] as TRaveText).Name = 'DataTextdEt'
666
      then
667
        (Page.Components[i] as TRaveText).Text := EditdEt.Text;
668
      if (Page.Components[i] as TRaveText).Name = 'DataTextEMc_EDc'
669
      then
670
        (Page.Components[i] as TRaveText).Text := EditEMc_EDc.Text;
671
      if (Page.Components[i] as TRaveText).Name = 'DataTextEMt_EDt'
672
      then
673
        (Page.Components[i] as TRaveText).Text := EditEMt_EDt.Text;
674
      if (Page.Components[i] as TRaveText).Name = 'DataTextENc_EMc'
675
      then
676
        (Page.Components[i] as TRaveText).Text := EditENc_EMc.Text;
677
      if (Page.Components[i] as TRaveText).Name = 'DataTextENt_EMt'
678
      then
679
        (Page.Components[i] as TRaveText).Text := EditENt_EMt.Text;
680
      if (Page.Components[i] as TRaveText).Name = 'DataTextdNc'
681
      then
682
        (Page.Components[i] as TRaveText).Text := EditdNc.Text;
683
      if (Page.Components[i] as TRaveText).Name = 'DataTextdNt'
684
      then
685
        (Page.Components[i] as TRaveText).Text := EditdNt.Text;
686
    end;
687
end;
688

    
689
procedure TFormPredictionDetail.FormCreate(Sender: TObject);
690
var
691
  ProximalUnit, EnergyUnit: String;
692
begin
693
  if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
694
  then
695
    Font.Name := 'Arial Unicode MS';
696
//  PanelButtons.Font.Size := PanelButtons.Font.Size + 2;
697
  PanelButtons.Font.Style := [fsBold];
698
  LabelName.Font.Style := [fsBold];
699
  EditName.Font.Style := [fsBold];
700
  TranslateComponent(Self);
701
  with FormOptions do
702
    if Expression = 0
703
    then // sur frais
704
    begin
705
      ProximalUnit := ComboBoxProximal.Items[Proximal];
706
      EnergyUnit := ComboBoxEnergy.Items[Energy];
707
    end
708
    else // sur mati?re s?che
709
    begin
710
      ProximalUnit := Format('%s %s', [ComboBoxProximal.Items[Proximal], _('DM')]);
711
      EnergyUnit := Format('%s %s', [ComboBoxEnergy.Items[Energy], _('DM')]);
712
    end;
713
  with FormOptions do
714
    LabelMS.Caption := Format('%s (%s)', [LabelMS.Caption, ComboBoxProximal.Items[Proximal]]);
715
  GroupBoxProximal.Caption := Format('%s (%s)', [GroupBoxProximal.Caption, ProximalUnit]);
716
  GroupBoxEnergy.Caption := Format('%s (%s)', [GroupBoxEnergy.Caption, EnergyUnit]);
717
  LabelRatio.Caption := Format('%s (%%)', [LabelRatio.Caption]);
718
  GroupBoxEnergyUtilization.Caption := Format('%s (%%)', [GroupBoxEnergyUtilization.Caption]);
719
  GroupBoxAzote.Caption := Format('%s (%%)', [GroupBoxAzote.Caption]);
720
end;
721

    
722
procedure TFormPredictionDetail.FormShow(Sender: TObject);
723
var
724
  Nb: Integer;
725
  EqCB, EqNDF, EqADF, NUri, EUri, Res, ResD, ECH4, dMO: Double;
726
  CurrentFormatSettings: TFormatSettings;
727
begin
728
  GetLocaleFormatSettings(GetUserDefaultLCID, CurrentFormatSettings);
729
  with DataModuleDeclaration do
730
  begin
731
    EditName.Text := FormPredictionCreate.EditName.Text;
732
    // Analyse proximale -> valeurs saisies
733
    RapMS := InputProximal(FormPredictionCreate.ValidateEditMS.AsFloat, 1, 0, FormPredictionCreate.ComboBoxMS.ItemIndex);
734
    MS := OutputProximal(RapMS, 1, 1, FormOptions.Proximal);
735
    EditMS.Text := FloatToStrF(MS, ffFixed, 15, FormOptions.ProximalDecimals, CurrentFormatSettings);
736
    if FormPredictionCreate.CheckBoxMM.Checked
737
    then
738
    begin
739
      MM := InputProximal(FormPredictionCreate.ValidateEditMM.AsFloat, RapMS, FormPredictionCreate.ComboBoxMM.ItemIndex div 2, FormPredictionCreate.ComboBoxMM.ItemIndex mod 2);
740
      EditMM.Text := FloatToStrF(OutputProximal(MM, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, CurrentFormatSettings);
741
    end;
742
    if FormPredictionCreate.CheckBoxMAT.Checked
743
    then
744
    begin
745
      MAT := InputProximal(FormPredictionCreate.ValidateEditMAT.AsFloat, RapMS, FormPredictionCreate.ComboBoxMAT.ItemIndex div 2, FormPredictionCreate.ComboBoxMAT.ItemIndex mod 2);
746
      EditMAT.Text := FloatToStrF(OutputProximal(MAT, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, CurrentFormatSettings);
747
    end;
748
    if FormPredictionCreate.CheckBoxMG.Checked
749
    then
750
    begin
751
      MG := InputProximal(FormPredictionCreate.ValidateEditMG.AsFloat, RapMS, FormPredictionCreate.ComboBoxMG.ItemIndex div 2, FormPredictionCreate.ComboBoxMG.ItemIndex mod 2);
752
      EditMG.Text := FloatToStrF(OutputProximal(MG, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, CurrentFormatSettings);
753
    end;
754
    if FormPredictionCreate.CheckBoxCB.Checked
755
    then
756
    begin
757
      CB := InputProximal(FormPredictionCreate.ValidateEditCB.AsFloat, RapMS, FormPredictionCreate.ComboBoxFibre.ItemIndex div 2, FormPredictionCreate.ComboBoxFibre.ItemIndex mod 2);
758
      EditCB.Text := FloatToStrF(OutputProximal(CB, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, CurrentFormatSettings);
759
    end;
760
    if FormPredictionCreate.CheckBoxNDF.Checked
761
    then
762
    begin
763
      NDF := InputProximal(FormPredictionCreate.ValidateEditNDF.AsFloat, RapMS, FormPredictionCreate.ComboBoxFibre.ItemIndex div 2, FormPredictionCreate.ComboBoxFibre.ItemIndex mod 2);
764
      EditNDF.Text := FloatToStrF(OutputProximal(NDF, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, CurrentFormatSettings);
765
    end;
766
    if FormPredictionCreate.CheckBoxADF.Checked
767
    then
768
    begin
769
      ADF := InputProximal(FormPredictionCreate.ValidateEditADF.AsFloat, RapMS, FormPredictionCreate.ComboBoxFibre.ItemIndex div 2, FormPredictionCreate.ComboBoxFibre.ItemIndex mod 2);
770
      EditADF.Text := FloatToStrF(OutputProximal(ADF, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, CurrentFormatSettings);
771
    end;
772
    if FormPredictionCreate.CheckBoxAmidon.Checked
773
    then
774
    begin
775
      Amidon := InputProximal(FormPredictionCreate.ValidateEditAmidon.AsFloat, RapMS, FormPredictionCreate.ComboBoxAmidon.ItemIndex div 2, FormPredictionCreate.ComboBoxAmidon.ItemIndex mod 2);
776
      EditAmidon.Text := FloatToStrF(OutputProximal(Amidon, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, CurrentFormatSettings);
777
    end;
778
    if FormPredictionCreate.CheckBoxSucres.Checked
779
    then
780
    begin
781
      Sucres := InputProximal(FormPredictionCreate.ValidateEditSucres.AsFloat, RapMS, FormPredictionCreate.ComboBoxSucres.ItemIndex div 2, FormPredictionCreate.ComboBoxSucres.ItemIndex mod 2);
782
      EditSucres.Text := FloatToStrF(OutputProximal(Sucres, RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, CurrentFormatSettings);
783
    end;
784
    if FormPredictionCreate.CheckBoxdMOv.Checked
785
    then
786
    begin
787
      dMOv := FormPredictionCreate.ValidateEditdMOv.AsFloat / 100;
788
      if FormPredictionCreate.CheckBoxMM.Checked
789
      then // MOdv = dMOv * MO avec MO = 1 - MM
790
        EditMOdv.Text := FloatToStrF(OutputProximal(dMOv * (1 - MM), RapMS, FormOptions.Expression, FormOptions.Proximal), ffFixed, 15, FormOptions.ProximalDecimals, CurrentFormatSettings);
791
    end;
792
    // Energie
793
    if FormPredictionCreate.CheckBoxEB.Checked
794
    then // EB fournie par l'utilisateur
795
    begin
796
      EB := InputEnergy(FormPredictionCreate.ValidateEditEB.AsFloat, RapMS, FormPredictionCreate.ComboBoxEB.ItemIndex div 2, FormPredictionCreate.ComboBoxEB.ItemIndex mod 2);
797
      EditEBc.Text := FloatToStrF(OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, CurrentFormatSettings);
798
    end
799
    else
800
      if FormPredictionCreate.CheckBoxMM.Checked and FormPredictionCreate.CheckBoxMAT.Checked and FormPredictionCreate.CheckBoxMG.Checked
801
      then // EB calcul?e
802
      begin
803
        if FormPredictionCreate.CheckBoxCB.Checked
804
        then
805
          if FormPredictionCreate.CheckBoxSucres.Checked
806
          then // Equation AVEC sucres
807
            EqCB := 17.56 + 5.51 * MAT + 21.48 * MG - 17.74 * MM + 2.59 * CB - 1.14 * Sucres
808
          else // Equation SANS sucres
809
            EqCB := 17.57 + 5.35 * MAT + 21.68 * MG - 18.61 * MM + 2.84 * CB
810
        else
811
          EqCB := 0;
812
        if FormPredictionCreate.CheckBoxNDF.Checked
813
        then
814
          if FormPredictionCreate.CheckBoxSucres.Checked
815
          then // Equation AVEC sucres
816
            EqNDF := 17.41 + 5.79 * MAT + 21.63 * MG - 18.12 * MM + 1.48 * NDF - 0.72 * Sucres
817
          else // Equation SANS sucres
818
            EqNDF := 17.40 + 5.73 * MAT + 21.76 * MG - 18.73 * MM + 1.61 * NDF
819
        else
820
          EqNDF := 0;
821
        if FormPredictionCreate.CheckBoxADF.Checked
822
        then
823
          if FormPredictionCreate.CheckBoxSucres.Checked
824
          then // Equation AVEC sucres
825
            EqADF := 17.56 + 5.45 * MAT + 21.50 * MG - 17.69 * MM + 2.16 * ADF - 1.15 * Sucres
826
          else // Equation SANS sucres
827
            EqADF := 17.58 + 5.29 * MAT + 21.71 * MG - 18.58 * MM + 2.38 * ADF
828
        else
829
          EqADF := 0;
830
        Nb := 0;
831
        if EqCB <> 0 then Inc(Nb);
832
        if EqNDF <> 0 then Inc(Nb);
833
        if EqADF <> 0 then Inc(Nb);
834
        if Nb = 0
835
        then // Equations sans valeur de fibre
836
          if FormPredictionCreate.CheckBoxAmidon.Checked
837
          then // Equation AVEC amidon
838
            if FormPredictionCreate.CheckBoxSucres.Checked
839
            then // Equation AVEC sucres
840
              EB := 18.88 + 4.24 * MAT + 20.25 * MG - 20.37 * MM - 1.42 * Amidon - 2.38 * Sucres
841
            else // Equation SANS sucres
842
              EB := 18.47 + 4.14 * MAT + 21.08 * MG - 19.64 * MM - 0.92 * Amidon
843
          else // Equation SANS amidon
844
            if FormPredictionCreate.CheckBoxSucres.Checked
845
            then // Equation AVEC sucres
846
              EB := 17.61 + 5.05 * MAT + 21.53 * MG - 15.06 * MM - 1.48 * Sucres
847
            else // Equation SANS sucres
848
              EB := 17.64 + 4.78 * MAT + 21.80 * MG - 15.88 * MM
849
        else // Moyenne des ?quations significatives
850
          EB := (EqCB + EqNDF + EqADF) / Nb;
851
        EditEBc.Text := FloatToStrF(OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, CurrentFormatSettings);
852
      end;
853
    BonusC := FormPredictionCreate.SpinEditBonusC.Value;
854
    EditBonusC.Text := FormPredictionCreate.SpinEditBonusC.Text;
855
    if FormPredictionCreate.CheckBoxdMOv.Checked
856
    then // Equation AVEC dMOv
857
    begin
858
      if FormPredictionCreate.CheckBoxCB.Checked
859
      then
860
        if FormPredictionCreate.CheckBoxMM.Checked
861
        then // Equation AVEC MM
862
          EqCB := 35.5 + 64.0 * dMOv - 68.0 * CB - 68.0 * MM
863
        else // Equation SANS MM
864
          EqCB := 30.1 + 66.3 * dMOv - 77.0 * CB
865
      else
866
        EqCB := 0;
867
      if FormPredictionCreate.CheckBoxADF.Checked
868
      then
869
        if FormPredictionCreate.CheckBoxMM.Checked
870
        then // Equation AVEC MM
871
          EqADF := 41.0 + 58.5 * dMOv - 74.0 * ADF - 64.0 * MM
872
        else // Equation SANS MM
873
          EqADF := 36.2 + 60.2 * dMOv - 82.0 * ADF
874
      else
875
        EqADF := 0;
876
      Nb := 0;
877
      if EqCB <> 0 then Inc(Nb);
878
      if EqADF <> 0 then Inc(Nb);
879
      if Nb = 0
880
      then // Equation sans valeur de fibre (dMOv seule)
881
        dEc := 97.6 * dMOv
882
      else // Moyenne des ?quations significatives
883
        dEc := (EqCB + EqADF) / Nb;
884
      EditdEc.Text := FloatToStrF(dEc + BonusC, ffFixed, 15, 1, CurrentFormatSettings);
885
    end
886
    else // Equation SANS dMOv
887
    begin
888
      if FormPredictionCreate.CheckBoxCB.Checked
889
      then
890
        if FormPredictionCreate.CheckBoxMM.Checked
891
        then // Equation AVEC MM
892
          EqCB := 98.0 - 160.0 * MM - 126.0 * CB
893
        else // Equation SANS MM
894
          EqCB := 90.1 - 156.6 * CB
895
      else
896
        EqCB := 0;
897
      if FormPredictionCreate.CheckBoxNDF.Checked
898
      then
899
        if FormPredictionCreate.CheckBoxMM.Checked
900
        then // Equation AVEC MM
901
          EqNDF := 102.6 - 106.1 * MM - 79.5 * NDF
902
        else // Equation SANS MM
903
          EqNDF := 98.3 - 90.1 * NDF
904
      else
905
        EqNDF := 0;
906
      if FormPredictionCreate.CheckBoxADF.Checked
907
      then
908
        if FormPredictionCreate.CheckBoxMM.Checked
909
        then // Equation AVEC MM
910
          EqADF := 97.9 - 146.2 * MM - 117.5 * ADF
911
        else // Equation SANS MM
912
          EqADF := 90.8 - 142.7 * ADF
913
      else
914
        EqADF := 0;
915
      Nb := 0;
916
      if EqCB <> 0 then Inc(Nb);
917
      if EqNDF <> 0 then Inc(Nb);
918
      if EqADF <> 0 then Inc(Nb);
919
      if Nb > 0
920
      then // Moyenne des ?quations significatives
921
      begin
922
        dEc := (EqCB + EqNDF + EqADF) / Nb;
923
        EditdEc.Text := FloatToStrF(dEc + BonusC, ffFixed, 15, 1, CurrentFormatSettings);
924
      end;
925
    end;
926
    if (EditEBc.Text <> '') and (EditdEc.Text <> '')
927
    then
928
    begin
929
      EDc := EB * (dEc + BonusC) / 100;
930
      EditEDc.Text := FloatToStrF(OutputEnergy(EDc, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, CurrentFormatSettings);
931
    end;
932
    if (EditEDc.Text <> '') and FormPredictionCreate.CheckBoxMM.Checked and FormPredictionCreate.CheckBoxMAT.Checked and FormPredictionCreate.CheckBoxMG.Checked and FormPredictionCreate.CheckBoxAmidon.Checked
933
    then
934
    begin
935
      NUri := 0.4 * MAT / 6.25;
936
      EUri := CALORIE * (0.046 + 7.4 * NUri);
937
      if FormPredictionCreate.CheckBoxSucres.Checked
938
      then // Equation AVEC sucres
939
        Res := 1 - MM - MAT - MG - Amidon - Sucres
940
      else // Equation SANS sucres (par d?faut, on estime les sucres ? 2 % MS)
941
        Res := 1 - MM - MAT - MG - Amidon - 0.02;
942
      ResD := 0.5 * Res;
943
      ECH4 := CALORIE * 0.16 * ResD;
944
      EMc := EDc - EUri - ECH4;
945
      EditEMc.Text := FloatToStrF(OutputEnergy(EMc, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, CurrentFormatSettings);
946
      if EDc <> 0
947
      then
948
        EditEMc_EDc.Text := FloatToStrF(EMc / EDc * 100, ffFixed, 15, 1, CurrentFormatSettings);
949
    end;
950
    if (EditEDc.Text <> '') and FormPredictionCreate.CheckBoxMAT.Checked and FormPredictionCreate.CheckBoxMG.Checked and FormPredictionCreate.CheckBoxAmidon.Checked
951
    then
952
    begin
953
      if FormPredictionCreate.CheckBoxCB.Checked
954
      then
955
        EqCB := 0.703 * EDc - 4.04 * MAT + 6.62 * MG + 1.97 * Amidon - 4.09 * CB
956
      else
957
        EqCB := 0;
958
      if FormPredictionCreate.CheckBoxNDF.Checked
959
      then
960
        EqNDF := 0.703 * EDc - 4.10 * MAT + 6.64 * MG + 1.97 * Amidon - 1.34 * NDF
961
      else
962
        EqNDF := 0;
963
      if FormPredictionCreate.CheckBoxADF.Checked
964
      then
965
        EqADF := 0.700 * EDc - 3.82 * MAT + 6.74 * MG + 2.02 * Amidon - 3.65 * ADF
966
      else
967
        EqADF := 0;
968
      Nb := 0;
969
      if EqCB <> 0 then Inc(Nb);
970
      if EqNDF <> 0 then Inc(Nb);
971
      if EqADF <> 0 then Inc(Nb);
972
      if Nb > 0
973
      then // Moyenne des ?quations significatives
974
      begin
975
        ENc := (EqCB + EqNDF + EqADF) / Nb;
976
        EditENc.Text := FloatToStrF(OutputEnergy(ENc, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, CurrentFormatSettings);
977
        if EMc <> 0
978
        then
979
          EditENc_EMc.Text := FloatToStrF(ENc / EMc * 100, ffFixed, 15, 1, CurrentFormatSettings);
980
      end;
981
    end;
982
    EditEBt.Text := EditEBc.Text;
983
    BonusT := FormPredictionCreate.SpinEditBonusT.Value;
984
    EditBonusT.Text := FormPredictionCreate.SpinEditBonusT.Text;
985
    if (EditEDc.Text <> '') and FormPredictionCreate.CheckBoxMM.Checked and FormPredictionCreate.CheckBoxMAT.Checked
986
    then
987
    begin
988
      dMO := (7.45 + 0.949 * dEc - 4.0 * MAT) / 100;
989
      EDt := EB * dEc / 100 + CALORIE * (1 - MM) * (1 - dMO);
990
      if (EditEBt.Text <> '') and (EB <> 0)
991
      then
992
      begin
993
        dEt := EDt / EB * 100;
994
        EditdEt.Text := FloatToStrF(dEt + BonusT, ffFixed, 15, 1, CurrentFormatSettings);
995
        // Recalculer EDt pour prendre en compte le bonus
996
        EDt := EB * (dEt + BonusT) / 100;
997
        EditEDt.Text := FloatToStrF(OutputEnergy(EDt, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, CurrentFormatSettings);
998
      end;
999
    end;
1000
    if (EditEDt.Text <> '') and FormPredictionCreate.CheckBoxMM.Checked and FormPredictionCreate.CheckBoxMAT.Checked and FormPredictionCreate.CheckBoxMG.Checked and FormPredictionCreate.CheckBoxAmidon.Checked
1001
    then
1002
    begin
1003
      NUri := 0.4 * MAT / 6.25;
1004
      EUri := CALORIE * (0.052 + 7.4 * NUri);
1005
      if FormPredictionCreate.CheckBoxSucres.Checked
1006
      then // Equation AVEC sucres
1007
        Res := 1 - MM - MAT - MG - Amidon - Sucres
1008
      else // Equation SANS sucres (par d?faut, on estime les sucres ? 2 % MS)
1009
        Res := 1 - MM - MAT - MG - Amidon - 0.02;
1010
      ResD := 0.6 * Res;
1011
      ECH4 := CALORIE * 0.32 * ResD;
1012
      EMt := EDt - EUri - ECH4;
1013
      EditEMt.Text := FloatToStrF(OutputEnergy(EMt, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, CurrentFormatSettings);
1014
      if EDt <> 0
1015
      then
1016
        EditEMt_EDt.Text := FloatToStrF(EMt / EDt * 100, ffFixed, 15, 1, CurrentFormatSettings);
1017
    end;
1018
    if (EditEDt.Text <> '') and FormPredictionCreate.CheckBoxMAT.Checked and FormPredictionCreate.CheckBoxMG.Checked and FormPredictionCreate.CheckBoxAmidon.Checked
1019
    then
1020
    begin
1021
      if FormPredictionCreate.CheckBoxCB.Checked
1022
      then
1023
        EqCB := 0.703 * EDt - 4.04 * MAT + 6.62 * MG + 1.97 * Amidon - 4.09 * CB
1024
      else
1025
        EqCB := 0;
1026
      if FormPredictionCreate.CheckBoxNDF.Checked
1027
      then
1028
        EqNDF := 0.703 * EDt - 4.10 * MAT + 6.64 * MG + 1.97 * Amidon - 1.34 * NDF
1029
      else
1030
        EqNDF := 0;
1031
      if FormPredictionCreate.CheckBoxADF.Checked
1032
      then
1033
        EqADF := 0.700 * EDt - 3.82 * MAT + 6.74 * MG + 2.02 * Amidon - 3.65 * ADF
1034
      else
1035
        EqADF := 0;
1036
      Nb := 0;
1037
      if EqCB <> 0 then Inc(Nb);
1038
      if EqNDF <> 0 then Inc(Nb);
1039
      if EqADF <> 0 then Inc(Nb);
1040
      if Nb > 0
1041
      then // Moyenne des ?quations significatives
1042
      begin
1043
        ENt := (EqCB + EqNDF + EqADF) / Nb;
1044
        EditENt.Text := FloatToStrF(OutputEnergy(ENt, RapMS, FormOptions.Expression, FormOptions.Energy), ffFixed, 15, FormOptions.EnergyDecimals, CurrentFormatSettings);
1045
        if EMt <> 0
1046
        then
1047
          EditENt_EMt.Text := FloatToStrF(ENt / EMt * 100, ffFixed, 15, 1, CurrentFormatSettings);
1048
      end;
1049
    end;
1050
    if EditEBc.Text <> ''
1051
    then
1052
      EditEBt_EBc.Text := FloatToStrF(100, ffFixed, 15, 1, CurrentFormatSettings);
1053
    if (EditEDt.Text <> '') and (EditEDc.Text <> '') and (EDc <> 0)
1054
    then
1055
      EditEDt_EDc.Text := FloatToStrF(EDt / EDc * 100, ffFixed, 15, 1, CurrentFormatSettings);
1056
    if (EditEMt.Text <> '') and (EditEMc.Text <> '') and (EMc <> 0)
1057
    then
1058
      EditEMt_EMc.Text := FloatToStrF(EMt / EMc * 100, ffFixed, 15, 1, CurrentFormatSettings);
1059
    if (EditENt.Text <> '') and (EditENc.Text <> '') and (ENc <> 0)
1060
    then
1061
      EditENt_ENc.Text := FloatToStrF(ENt / ENc * 100, ffFixed, 15, 1, CurrentFormatSettings);
1062
    // Digestibilit? f?cale de l'azote
1063
    if FormPredictionCreate.CheckBoxMAT.Checked
1064
    then
1065
    begin
1066
      if FormPredictionCreate.CheckBoxCB.Checked
1067
      then
1068
        EqCB := 76.8 + 69.0 * MAT - 122.0 * CB
1069
      else
1070
        EqCB := 0;
1071
      if FormPredictionCreate.CheckBoxNDF.Checked
1072
      then
1073
        EqNDF := 81.3 + 79.0 * MAT - 69.0 * NDF
1074
      else
1075
        EqNDF := 0;
1076
      if FormPredictionCreate.CheckBoxADF.Checked
1077
      then
1078
        EqADF := 77.4 + 70.0 * MAT - 116.0 * ADF
1079
      else
1080
        EqADF := 0;
1081
      Nb := 0;
1082
      if EqCB <> 0 then Inc(Nb);
1083
      if EqNDF <> 0 then Inc(Nb);
1084
      if EqADF <> 0 then Inc(Nb);
1085
      if Nb > 0
1086
      then // Moyenne des ?quations significatives
1087
      begin
1088
        dNc := (EqCB + EqNDF + EqADF) / Nb;
1089
        EditdNc.Text := FloatToStrF(dNc, ffFixed, 15, 1, CurrentFormatSettings);
1090
      end;
1091
      if FormPredictionCreate.CheckBoxCB.Checked
1092
      then
1093
        EqCB := 77.9 + 77.0 * MAT - 87.0 * CB
1094
      else
1095
        EqCB := 0;
1096
      if FormPredictionCreate.CheckBoxNDF.Checked
1097
      then
1098
        EqNDF := 79.9 + 86.0 * MAT - 44.0 * NDF
1099
      else
1100
        EqNDF := 0;
1101
      if FormPredictionCreate.CheckBoxADF.Checked
1102
      then
1103
        EqADF := 78.3 + 78.0 * MAT - 83.0 * ADF
1104
      else
1105
        EqADF := 0;
1106
      Nb := 0;
1107
      if EqCB <> 0 then Inc(Nb);
1108
      if EqNDF <> 0 then Inc(Nb);
1109
      if EqADF <> 0 then Inc(Nb);
1110
      if Nb > 0
1111
      then // Moyenne des ?quations significatives
1112
      begin
1113
        dNt := (EqCB + EqNDF + EqADF) / Nb;
1114
        EditdNt.Text := FloatToStrF(dNt, ffFixed, 15, 1, CurrentFormatSettings);
1115
      end;
1116
    end;
1117
  end;
1118
end;
1119

    
1120
end.