Statistiques
| Révision:

root / UnitFeedDetail.pas @ 4

Historique | Voir | Annoter | Télécharger (31,891 ko)

1 1 avalancogn
unit UnitFeedDetail;
2
3
{$WARN SYMBOL_PLATFORM OFF}
4
5
interface
6
7
uses
8
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
9
  Dialogs, gnugettext, StdCtrls, Mask, DB, DBCtrls, JvExStdCtrls, JvEdit,
10
  JvValidateEdit, ExtCtrls, RpBase, RpSystem, RpRender, RpRenderPDF, RpRave,
11
  RpDefine, RpCon, RpConDS, JvCsvData, RvClass, RvCsStd, RvCsData, ImgList,
12
  ComCtrls, ToolWin, ActnList, JvButton, JvCtrls, XMLIntf, XMLDoc, RpDevice;
13
14
type
15
  TFormFeedDetail = class(TForm)
16
    DBEditName: TDBEdit;
17
    GroupBoxProximal: TGroupBox;
18
    DBEditMS: TDBEdit;
19
    DBEditMAT: TDBEdit;
20
    DBEditCB: TDBEdit;
21
    DBEditMG: TDBEdit;
22
    DBEditMM: TDBEdit;
23
    DBEditNDF: TDBEdit;
24
    DBEditADF: TDBEdit;
25
    DBEditADL: TDBEdit;
26
    DBEditAmidon: TDBEdit;
27
    DBEditSucres: TDBEdit;
28
    GroupBoxAA: TGroupBox;
29
    GroupBoxMinerals: TGroupBox;
30
    DBEditCa: TDBEdit;
31
    DBEditP: TDBEdit;
32
    DBEditPd: TDBEdit;
33
    GroupBoxEnergyUtilization: TGroupBox;
34
    DBEditdEc: TDBEdit;
35
    DBEditdEt: TDBEdit;
36
    DBEditEMc_EDc: TDBEdit;
37
    DBEditEMt_EDt: TDBEdit;
38
    DBEditENc_EMc: TDBEdit;
39
    DBEditENt_EMt: TDBEdit;
40
    GroupBoxEnergy: TGroupBox;
41
    DBEditEBc: TDBEdit;
42
    DBEditEBt: TDBEdit;
43
    DBEditEDc: TDBEdit;
44
    DBEditEDt: TDBEdit;
45
    DBEditEMc: TDBEdit;
46
    DBEditEMt: TDBEdit;
47
    DBEditENc: TDBEdit;
48
    DBEditENt: TDBEdit;
49
    DBEditEDt_EDc: TDBEdit;
50
    DBEditEMt_EMc: TDBEdit;
51
    DBEditENt_ENc: TDBEdit;
52
    ValidateEditEBt_EBc: TJvValidateEdit;
53
    DBEditLysd_ENc: TDBEdit;
54
    DBEditLysd_ENt: TDBEdit;
55
    DBEditCa_Pd: TDBEdit;
56
    DBEditLys: TDBEdit;
57
    DBEditLysd: TDBEdit;
58
    DBEditTyr: TDBEdit;
59
    DBEditTyrd: TDBEdit;
60
    DBEditThr: TDBEdit;
61
    DBEditThrd: TDBEdit;
62
    DBEditPheTyr: TDBEdit;
63
    DBEditPheTyrd: TDBEdit;
64
    DBEditMet: TDBEdit;
65
    DBEditMetd: TDBEdit;
66
    DBEditHis: TDBEdit;
67
    DBEditHisd: TDBEdit;
68
    DBEditCys: TDBEdit;
69
    DBEditCysd: TDBEdit;
70
    DBEditArg: TDBEdit;
71
    DBEditArgd: TDBEdit;
72
    DBEditMetCys: TDBEdit;
73
    DBEditMetCysd: TDBEdit;
74
    DBEditAla: TDBEdit;
75
    DBEditAlad: TDBEdit;
76
    DBEditTrp: TDBEdit;
77
    DBEditTrpd: TDBEdit;
78
    DBEditAsp: TDBEdit;
79
    DBEditAspd: TDBEdit;
80
    DBEditIle: TDBEdit;
81
    DBEditIled: TDBEdit;
82
    DBEditGlu: TDBEdit;
83
    DBEditGlud: TDBEdit;
84
    DBEditVal: TDBEdit;
85
    DBEditVald: TDBEdit;
86
    DBEditGly: TDBEdit;
87
    DBEditGlyd: TDBEdit;
88
    DBEditLeu: TDBEdit;
89
    DBEditLeud: TDBEdit;
90
    DBEditSer: TDBEdit;
91
    DBEditSerd: TDBEdit;
92
    DBEditPhe: TDBEdit;
93
    DBEditPhed: TDBEdit;
94
    DBEditPro: TDBEdit;
95
    DBEditProd: TDBEdit;
96
    DBEditTyrd_Lysd: TDBEdit;
97
    DBEditPheTyrd_Lysd: TDBEdit;
98
    DBEditMetd_Lysd: TDBEdit;
99
    DBEditHisd_Lysd: TDBEdit;
100
    DBEditCysd_Lysd: TDBEdit;
101
    DBEditArgd_Lysd: TDBEdit;
102
    DBEditMetCysd_Lysd: TDBEdit;
103
    DBEditAlad_Lysd: TDBEdit;
104
    DBEditTrpd_Lysd: TDBEdit;
105
    DBEditAspd_Lysd: TDBEdit;
106
    DBEditIled_Lysd: TDBEdit;
107
    DBEditGlud_Lysd: TDBEdit;
108
    DBEditVald_Lysd: TDBEdit;
109
    DBEditGlyd_Lysd: TDBEdit;
110
    DBEditLeud_Lysd: TDBEdit;
111
    DBEditSerd_Lysd: TDBEdit;
112
    DBEditPhed_Lysd: TDBEdit;
113
    DBEditProd_Lysd: TDBEdit;
114
    ValidateEditLysd_Lysd: TJvValidateEdit;
115
    DBEditPd_ENc: TDBEdit;
116
    DBEditPd_ENt: TDBEdit;
117
    DBEditBonusC: TDBEdit;
118
    GroupBoxAzote: TGroupBox;
119
    DBEditdNc: TDBEdit;
120
    DBEditdNt: TDBEdit;
121
    DBEditBonusT: TDBEdit;
122
    DBMemoDescription: TDBMemo;
123
    SaveDialogExport: TSaveDialog;
124
    RvDataSetConnectionComposition: TRvDataSetConnection;
125
    RvDataSetConnectionFeeds: TRvDataSetConnection;
126
    RvProjectReport: TRvProject;
127
    RvSystemReport: TRvSystem;
128
    PanelMain: TPanel;
129
    PanelButtons: TPanel;
130
    ImageListIcons: TImageList;
131
    ActionListButtons: TActionList;
132
    ActionModify: TAction;
133
    ActionDelete: TAction;
134
    ActionPrint: TAction;
135
    ActionXML: TAction;
136
    ActionHelp: TAction;
137
    ActionClose: TAction;
138
    ActionGraphs: TAction;
139
    LabelDescription: TLabel;
140
    LabelMS: TLabel;
141
    LabelName: TLabel;
142
    LabelPresentation: TLabel;
143
    LabelAADig: TLabel;
144
    LabelAATot: TLabel;
145
    LabelIdealProtein: TLabel;
146
    LabelLys: TLabel;
147
    LabelTyr: TLabel;
148
    LabelThr: TLabel;
149
    LabelPheTyr: TLabel;
150
    LabelMet: TLabel;
151
    LabelHis: TLabel;
152
    LabelCys: TLabel;
153
    LabelArg: TLabel;
154
    LabelMetCys: TLabel;
155
    LabelAla: TLabel;
156
    LabelTrp: TLabel;
157
    LabelAsp: TLabel;
158
    LabelIle: TLabel;
159
    LabelGlu: TLabel;
160
    LabelVal: TLabel;
161
    LabelGly: TLabel;
162
    LabelLeu: TLabel;
163
    LabelSer: TLabel;
164
    LabelPhe: TLabel;
165
    LabelPro: TLabel;
166
    LabelCrois4: TLabel;
167
    LabelTruie4: TLabel;
168
    LabeldN: TLabel;
169
    LabelEB: TLabel;
170
    LabelED: TLabel;
171
    LabelEM: TLabel;
172
    LabelEN: TLabel;
173
    LabelCrois1: TLabel;
174
    LabelTruie1: TLabel;
175
    LabelRatio: TLabel;
176
    LabeldE: TLabel;
177
    LabelEM_ED: TLabel;
178
    LabelEN_EM: TLabel;
179
    LabelCrois2: TLabel;
180
    LabelTruie2: TLabel;
181
    LabelLysd_EN: TLabel;
182
    LabelBonus: TLabel;
183
    LabelCa: TLabel;
184
    LabelP: TLabel;
185
    LabelPd: TLabel;
186
    LabelCa_Pd: TLabel;
187
    LabelPd_EN: TLabel;
188
    LabelMAT: TLabel;
189
    LabelCB: TLabel;
190
    LabelMG: TLabel;
191
    LabelMM: TLabel;
192
    LabelNDF: TLabel;
193
    LabelADF: TLabel;
194
    LabelADL: TLabel;
195
    LabelAmidon: TLabel;
196
    LabelSucres: TLabel;
197
    EditPresentation: TEdit;
198
    JvImgBtnClose: TJvImgBtn;
199
    JvImgBtnHelp: TJvImgBtn;
200
    JvImgBtnXML: TJvImgBtn;
201
    JvImgBtnPrint: TJvImgBtn;
202
    JvImgBtnDelete: TJvImgBtn;
203
    JvImgBtnModify: TJvImgBtn;
204
    JvImgBtnGraphs: TJvImgBtn;
205
    PanelHead: TPanel;
206 3 avalancogn
    LabelNa: TLabel;
207
    LabelK: TLabel;
208
    LabelCl: TLabel;
209
    LabelBE: TLabel;
210
    DBEditNa: TDBEdit;
211
    DBEditK: TDBEdit;
212
    DBEditCl: TDBEdit;
213
    DBEditBE: TDBEdit;
214 1 avalancogn
    procedure FormCreate(Sender: TObject);
215
    procedure FormShow(Sender: TObject);
216
    procedure ActionModifyExecute(Sender: TObject);
217
    procedure ActionDeleteExecute(Sender: TObject);
218
    procedure ActionGraphsExecute(Sender: TObject);
219
    procedure ActionPrintExecute(Sender: TObject);
220
    procedure ActionXMLExecute(Sender: TObject);
221
    procedure ActionHelpExecute(Sender: TObject);
222
    procedure ActionCloseExecute(Sender: TObject);
223
  private
224
    { D?clarations priv?es }
225
    procedure BuildReport;
226
    procedure EditEmpty(Edit: TJvValidateEdit);
227
  public
228
    { D?clarations publiques }
229
  end;
230
231
var
232
  FormFeedDetail: TFormFeedDetail;
233
234
implementation
235
236
uses
237
  UnitDeclaration, UnitOptions, UnitFeedEdition, UnitFeedCharts;
238
239
{$R *.dfm}
240
241
procedure TFormFeedDetail.ActionCloseExecute(Sender: TObject);
242
begin
243
  ModalResult := mrClose;
244
end;
245
246
procedure TFormFeedDetail.ActionXMLExecute(Sender: TObject);
247
var
248
  i: Integer;
249
  USFormatSettings: TFormatSettings;
250
  XMLDoc: IXMLDocument;
251
  Workbook, Worksheet, Table, Row: IXMLNode;
252
253
  procedure CellData(Row: IXMLNode; Value, Format: string);
254
  var
255
    Cell, Data: IXMLNode;
256
  begin
257
    Cell := Row.AddChild('Cell');
258
    Data := Cell.AddChild('Data');
259
    Data.Attributes['ss:Type'] := Format;
260
    Data.Text := Value;
261
  end;
262
263
begin
264
  if SaveDialogExport.Execute
265
  then
266
  begin
267
    GetLocaleFormatSettings(1033, USFormatSettings);
268
    XMLDoc := TXMLDocument.Create(nil);
269
    try
270
      XMLDoc.XML.Clear;
271
      XMLDoc.XML.Add('<?xml version="1.0" encoding="UTF-8" ?>');
272
      XMLDoc.XML.Add('<?mso-application progid="Excel.Sheet"?>');
273
      XMLDoc.XML.Add('<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet">');
274
      XMLDoc.XML.Add('</Workbook>');
275
      XMLDoc.Active := True;
276
      Workbook := XMLDoc.DocumentElement;
277
      Workbook.DeclareNamespace('o', 'urn:schemas-microsoft-com:office:office');
278
      Workbook.DeclareNamespace('x', 'urn:schemas-microsoft-com:office:excel');
279
      Workbook.DeclareNamespace('ss', 'urn:schemas-microsoft-com:office:spreadsheet');
280
      Workbook.DeclareNamespace('html', 'http://www.w3.org/TR/REC-html40');
281
      Worksheet := Workbook.AddChild('Worksheet');
282
      Worksheet.SetAttributeNS('ss:Name', Workbook.FindNamespaceURI('ss'), Caption);
283
      Table := Worksheet.AddChild('Table');
284
      // Titre
285
      Row := Table.AddChild('Row');
286
      CellData(Row, _('Label'), 'String');
287
      CellData(Row, _('Value'), 'String');
288
      CellData(Row, _('Unit'), 'String');
289
      // Donn?es
290
      with DataModuleDeclaration do
291
        for i := 0 to ClientDataSetFeeds.FieldCount - 1 do
292 4 avalancogn
          if not (i in [0, 2, 7, 106..108, 110..113])
293 1 avalancogn
          then // Champs export?s
294
          begin
295
            Row := Table.AddChild('Row');
296
            // Label
297
            CellData(Row, _(ClientDataSetFeeds.Fields[i].DisplayLabel), 'String');
298
            // Value
299
            case i of
300
              1:
301
                CellData(Row, ClientDataSetFeeds.Fields[i].AsWideString, 'String');
302
              3: // Pr?sentation
303
                if ClientDataSetFeedsPresentation.Value = 0
304
                then
305
                  CellData(Row, _('Mash'), 'String')
306
                else
307
                  CellData(Row, _('Pellet'), 'String');
308
              6, 8..16:
309
                if not ClientDataSetFeeds.Fields[i].IsNull
310
                then
311
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
312
                else
313
                  CellData(Row, '', 'String');
314
              17, 19, 21, 23, 25, 27, 29:
315
                if not ClientDataSetFeeds.Fields[i].IsNull
316
                then
317
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
318
                else
319
                  CellData(Row, '', 'String');
320 4 avalancogn
              4, 5, 18, 20, 22, 24, 26, 28, 30..34, 103:
321 1 avalancogn
                if not ClientDataSetFeeds.Fields[i].IsNull
322
                then
323
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, 1, USFormatSettings), 'Number')
324
                else
325
                  CellData(Row, '', 'String');
326
              35..54, 55..74:
327
                if not ClientDataSetFeeds.Fields[i].IsNull
328
                then
329
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, FormOptions.AADecimals, USFormatSettings), 'Number')
330
                else
331
                  CellData(Row, '', 'String');
332 4 avalancogn
              75..76, 104..105:
333 1 avalancogn
                if not ClientDataSetFeeds.Fields[i].IsNull
334
                then
335
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, 2, USFormatSettings), 'Number')
336
                else
337
                  CellData(Row, '', 'String');
338 4 avalancogn
              77..95, 109:
339 1 avalancogn
                if not ClientDataSetFeeds.Fields[i].IsNull
340
                then
341
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, 0, USFormatSettings), 'Number')
342
                else
343
                  CellData(Row, '', 'String');
344 4 avalancogn
              96..100, 102:
345 1 avalancogn
                if not ClientDataSetFeeds.Fields[i].IsNull
346
                then
347
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, FormOptions.MineralsDecimals, USFormatSettings), 'Number')
348
                else
349
                  CellData(Row, '', 'String');
350 4 avalancogn
              101:
351
                if not ClientDataSetIngredients.Fields[i].IsNull
352
                then
353
                  CellData(Row, FloatToStrF(ClientDataSetIngredients.Fields[i].AsFloat, ffFixed, 15, 2, USFormatSettings), 'Number')
354
                else
355
                  CellData(Row, '', 'String');
356 1 avalancogn
            end;
357
            // Unit
358
            case i of
359
              6: // MS
360
                CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String');
361
              8..16: // Analyse proximale
362
                if FormOptions.Expression = 0
363
                then // sur frais
364
                  CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
365
                else // sur mati?re s?che
366
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
367
              17, 19, 21, 23, 25, 27, 29: // Energie
368
                if FormOptions.Expression = 0
369
                then // sur frais
370
                  CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
371
                else // sur mati?re s?che
372
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
373 4 avalancogn
              4..5, 18, 20, 22, 24, 26, 28, 30..34, 77..95, 103: // %
374 1 avalancogn
                CellData(Row, '%', 'String');
375
              35..54, 55..74: // AA
376
                if FormOptions.Expression = 0
377
                then // sur frais
378
                  CellData(Row, FormOptions.ComboBoxAA.Items[FormOptions.AA], 'String')
379
                else // sur mati?re s?che
380
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxAA.Items[FormOptions.AA], _('DM')]), 'String');
381 4 avalancogn
              75..76, 104..105: // Lysd/EN ou Pd/EN
382 1 avalancogn
                if FormOptions.Energy = 0
383
                then // MJ
384
                  CellData(Row, _('g/MJ'), 'String')
385
                else // kcal
386
                  CellData(Row, _('g/1000kcal'), 'String');
387 4 avalancogn
              96..100, 102: // Min?raux
388 1 avalancogn
                if FormOptions.Expression = 0
389
                then // sur frais
390
                  CellData(Row, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], 'String')
391
                else // sur mati?re s?che
392
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], _('DM')]), 'String');
393 4 avalancogn
              101: // %
394
                if FormOptions.Expression = 0
395
                then // sur frais
396
                  CellData(Row, _('mEq/kg'), 'String')
397
                else // sur mati?re s?che
398
                  CellData(Row, Format('%s %s', [_('mEq/kg'), _('DM')]), 'String');
399
              109:
400 1 avalancogn
                CellData(Row, _('IU/kg'), 'String');
401
            end;
402
          end;
403
      Worksheet := Workbook.AddChild('Worksheet');
404
      Worksheet.SetAttributeNS('ss:Name', Workbook.FindNamespaceURI('ss'), _('Ingredients'));
405
      Table := Worksheet.AddChild('Table');
406
      with DataModuleDeclaration do
407
      begin
408
        // Titres
409
        Row := Table.AddChild('Row');
410
        CellData(Row, _('Diet'), 'String');
411
        CellData(Row, ClientDataSetFeedsName.Value, 'String');
412
        Row := Table.AddChild('Row');
413
        Row := Table.AddChild('Row');
414
        CellData(Row, _('Ingredient'), 'String');
415
        CellData(Row, _('Dry matter'), 'String');
416
        CellData(Row, _('Incorporation level'), 'String');
417
        Row := Table.AddChild('Row');
418
        CellData(Row, '', 'String');
419
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String');
420
        CellData(Row, FormOptions.ComboBoxIncorporation.Items[FormOptions.Incorporation], 'String');
421
        // Donn?es
422
        ClientDataSetComposition.Filter := Format('Feed = %d', [ClientDataSetFeedsId.Value]);
423
        ClientDataSetComposition.Filtered := True;
424
        ClientDataSetComposition.First;
425
        while not ClientDataSetComposition.Eof do
426
        begin
427
          Row := Table.AddChild('Row');
428
          CellData(Row, ClientDataSetCompositionIngredientName.Value, 'String');
429
          CellData(Row, FloatToStrF(ClientDataSetCompositionMS.AsFloat, ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number');
430
          CellData(Row, FloatToStrF(ClientDataSetCompositionLevel.AsFloat, ffFixed, 15, FormOptions.IncorporationDecimals, USFormatSettings), 'Number');
431
          ClientDataSetComposition.Next;
432
        end;
433
        ClientDataSetComposition.Filtered := False;
434
        ClientDataSetComposition.Filter := '';
435
        if not ClientDataSetFeedsPhytaseId.IsNull
436
        then // Phytase
437
        begin
438
          Row := Table.AddChild('Row');
439
          CellData(Row, Format('%s %1.2f', [_('Phytase'), ClientDataSetFeedsPhytaseType.Value]), 'String');
440
          CellData(Row, '', 'String');
441
          CellData(Row, FloatToStrF(ClientDataSetFeedsPhytaseLevel.AsFloat, ffFixed, 15, FormOptions.IncorporationDecimals, USFormatSettings), 'Number');
442
        end;
443
      end;
444
      XMLDoc.SaveToFile(SaveDialogExport.FileName);
445
      XmlDoc.Active := False;
446
    finally
447
      XMLDoc := nil;
448
    end;
449
  end;
450
end;
451
452
procedure TFormFeedDetail.ActionDeleteExecute(Sender: TObject);
453
var
454
  FeedName: String;
455
begin
456
  with DataModuleDeclaration do
457
    if MessageDlg(_('Are sure you want to delete this record?') + sLineBreak + _('This action could not be canceled.'), mtConfirmation, [mbYes, mbNo], 0) = mrYes
458
    then
459
    begin
460
      ClientDataSetFeeds.DisableControls;
461
      try
462
        FeedName := ClientDataSetFeedsName.Value;
463
        // Supprimer la composition du r?gime
464
        DBUser.BeginTransaction;
465
        try
466
          DBUser.ExecSQL('DELETE FROM Composition '
467
            + Format('WHERE Feed = %d', [ClientDataSetFeedsId.Value]));
468
          DBUser.Commit;
469
        except
470
          DBUser.RollBack;
471
          MessageDlg(Format(_('Unknown error: %s %s %s'), ['UnitFeedDetail', 'ActionDeleteExecute', 'DBUser (DELETE FROM Composition)']), mtError, [mbOK], 0);
472
          Exit;
473
        end;
474
        // Suprimer de ClientDataSetComposition
475
        ClientDataSetComposition.Filter := Format('Feed = %d', [ClientDataSetFeedsId.Value]);
476
        ClientDataSetComposition.Filtered := True;
477
        ClientDataSetComposition.First;
478
        while not ClientDataSetComposition.Eof do
479
          ClientDataSetComposition.Delete;
480
        ClientDataSetComposition.Filtered := False;
481
        ClientDataSetComposition.Filter := '';
482
        // Suprimer l'aliment
483
        DBUser.BeginTransaction;
484
        try
485
          DBUser.ExecSQL('DELETE FROM Feeds '
486
            + Format('WHERE Id = %d', [ClientDataSetFeedsId.Value]));
487
          DBUser.Commit;
488
        except
489
          DBUser.RollBack;
490
          MessageDlg(Format(_('Unknown error: %s %s %s'), ['UnitFeedDetail', 'ActionDeleteExecute', 'DBUser (DELETE FROM Feeds)']), mtError, [mbOK], 0);
491
          Exit;
492
        end;
493
        // Suprimer de ClientDataSetFeeds
494
        ClientDataSetFeeds.Delete;
495
        // Suprimer le nom de la liste des r?gimes
496
        FeedList.Delete(FeedList.IndexOf(FeedName));
497
        // Fermer la fen?tre
498
        Close;
499
      finally
500
        ClientDataSetFeeds.EnableControls;
501
      end;
502
    end;
503
end;
504
505
procedure TFormFeedDetail.ActionGraphsExecute(Sender: TObject);
506
begin
507
  FormFeedCharts := TFormFeedCharts.Create(nil);
508
  try
509
    FormFeedCharts.ShowModal;
510
  finally
511
    FormFeedCharts.Release;
512
  end;
513
end;
514
515
procedure TFormFeedDetail.ActionHelpExecute(Sender: TObject);
516
begin
517
  Application.HelpContext(HelpContext);
518
end;
519
520
procedure TFormFeedDetail.ActionModifyExecute(Sender: TObject);
521
begin
522
  FormFeedEdition := TFormFeedEdition.Create(nil);
523
  try
524
    FormFeedEdition.ShowModal;
525
  finally
526
    FormFeedEdition.Release;
527
  end;
528
//  with DataModuleDeclaration do
529
//    Hint := ClientDataSetFeedsDescription.Value;
530
end;
531
532
procedure TFormFeedDetail.ActionPrintExecute(Sender: TObject);
533
begin
534
  if RpDev.PrinterSetupDialog
535
  then
536
  begin
537
    RvSystemReport.DoNativeOutput := false;
538
    RvSystemReport.DefaultDest := rdPrinter;
539
    RvSystemReport.RenderObject := nil;
540
    RvSystemReport.OutputFileName := '';
541
    RvProjectReport.Open;
542
    BuildReport;
543
    RvProjectReport.Execute;
544
    RvProjectReport.Close;
545
    with DataModuleDeclaration do
546
    begin
547
      ClientDataSetComposition.Filtered := False;
548
      ClientDataSetComposition.Filter := '';
549
    end;
550
  end;
551
end;
552
553
procedure TFormFeedDetail.BuildReport;
554
var
555
  i: Integer;
556
  Page: TRavePage;
557
begin
558
  with DataModuleDeclaration do
559
  begin
560
    if ClientDataSetFeeds.Eof
561
    then // Bug : seconde page blanche
562
      if ClientDataSetIngredients.RecordCount > 1
563
      then
564
      begin
565
        ClientDataSetIngredients.Prior;
566
        ClientDataSetIngredients.Next;
567
      end
568
      else
569
        ClientDataSetIngredients.First;
570
    ClientDataSetComposition.Filter := Format('Feed = %d', [ClientDataSetFeedsId.Value]);
571
    ClientDataSetComposition.Filtered := True;
572
    // Taux d'incorporation total
573
    ClientDataSetFeeds.Edit;
574
    if ClientDataSetComposition.Aggregates[0].Value = Null
575
    then
576
      ClientDataSetFeedsLevelSum.Clear
577
    else
578
      ClientDataSetFeedsLevelSum.Value := ClientDataSetComposition.Aggregates[0].Value;
579
    ClientDataSetFeeds.Post;
580
  end;
581
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportFeed.PageFeed1', nil) as TRavePage;
582
  for i := 0 to Page.ComponentCount - 1 do
583
  begin
584
    if Page.Components[i].ClassNameIs('TRaveText')
585
    then // Traduire
586
    begin
587
      if (Page.Components[i] as TRaveText).Name = 'TextPresentation2'
588
      then
589
        if DataModuleDeclaration.ClientDataSetFeedsPresentation.Value = 0
590
        then
591
          (Page.Components[i] as TRaveText).Text := 'Mash'
592
        else
593
          (Page.Components[i] as TRaveText).Text := 'Pellet';
594
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
595
      then
596
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
597
      TranslateComponent(Page.Components[i]);
598
      if (Page.Components[i] as TRaveText).Name = 'TextMS'
599
      then
600
        with FormOptions do
601
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, ComboBoxProximal.Items[Proximal]]);
602
      if (Page.Components[i] as TRaveText).Name = 'TextUnitProximal'
603
      then
604
        with FormOptions do
605
          if Expression = 0
606
          then // sur frais
607
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxProximal.Items[Proximal]])
608
          else // sur mati?re s?che
609
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxProximal.Items[Proximal], _('DM')]);
610
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyC'
611
      then
612
        with FormOptions do
613
          if Expression = 0
614
          then // sur frais
615
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxEnergy.Items[Energy]])
616
          else // sur mati?re s?che
617
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxEnergy.Items[Energy], _('DM')]);
618
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyT'
619
      then
620
        with FormOptions do
621
          if Expression = 0
622
          then // sur frais
623
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxEnergy.Items[Energy]])
624
          else // sur mati?re s?che
625
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxEnergy.Items[Energy], _('DM')]);
626
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyRatio'
627
      then
628
        (Page.Components[i] as TRaveText).Text := '(%)';
629
      if (Page.Components[i] as TRaveText).Name = 'TextEBt_EBc'
630
      then
631
        (Page.Components[i] as TRaveText).Text := ValidateEditEBt_EBc.Text;
632
      if (Page.Components[i] as TRaveText).Name = 'TextBonus'
633
      then
634
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
635
      if (Page.Components[i] as TRaveText).Name = 'TextdE'
636
      then
637
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
638
      if (Page.Components[i] as TRaveText).Name = 'TextEM_ED'
639
      then
640
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
641
      if (Page.Components[i] as TRaveText).Name = 'TextEN_EM'
642
      then
643
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
644
    end;
645
    if Page.Components[i].ClassNameIs('TRaveDataMemo') and (Screen.Fonts.IndexOf('Arial Unicode MS') <> -1)
646
    then
647
      (Page.Components[i] as TRaveDataMemo).Font.Name := 'Arial Unicode MS';
648
    if Page.Components[i].ClassNameIs('TRaveDataText') and (Screen.Fonts.IndexOf('Arial Unicode MS') <> -1)
649
    then
650
      (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
651
  end;
652
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportFeed.PageFeed2', nil) as TRavePage;
653
  for i := 0 to Page.ComponentCount - 1 do
654
  begin
655
    if Page.Components[i].ClassNameIs('TRaveText')
656
    then // Traduire
657
    begin
658
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
659
      then
660
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
661
      TranslateComponent(Page.Components[i]);
662
      if (Page.Components[i] as TRaveText).Name = 'TextdN'
663
      then
664
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
665
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAATot'
666
      then
667
        with FormOptions do
668
          if Expression = 0
669
          then // sur frais
670
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxAA.Items[AA]])
671
          else // sur mati?re s?che
672
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxAA.Items[AA], _('DM')]);
673
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAADig'
674
      then
675
        with FormOptions do
676
          if Expression = 0
677
          then // sur frais
678
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxAA.Items[AA]])
679
          else // sur mati?re s?che
680
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxAA.Items[AA], _('DM')]);
681
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAAProtId'
682
      then
683
        (Page.Components[i] as TRaveText).Text := '(%)';
684
      if (Page.Components[i] as TRaveText).Name = 'TextLysd_Lysd'
685
      then
686
        (Page.Components[i] as TRaveText).Text := ValidateEditLysd_Lysd.Text;
687
      if (Page.Components[i] as TRaveText).Name = 'TextUnitLysd_EN'
688
      then
689
        if FormOptions.Energy = 0
690
        then // MJ
691
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/MJ')])
692
        else // kcal
693
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/1000kcal')]);
694
      if (Page.Components[i] as TRaveText).Name = 'TextUnitMinerals'
695
      then
696
        with FormOptions do
697
          if Expression = 0
698
          then // sur frais
699
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxMinerals.Items[Minerals]])
700
          else // sur mati?re s?che
701
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxMinerals.Items[Minerals], _('DM')]);
702
      if (Page.Components[i] as TRaveText).Name = 'TextUnitPd_EN'
703
      then
704
        if FormOptions.Energy = 0
705
        then // MJ
706
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/MJ')])
707
        else // kcal
708
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/1000kcal')]);
709
    end;
710
    if Page.Components[i].ClassNameIs('TRaveDataText') and (Screen.Fonts.IndexOf('Arial Unicode MS') <> -1)
711
    then
712
      (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
713
  end;
714
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportFeed.PageComposition', nil) as TRavePage;
715
  for i := 0 to Page.ComponentCount - 1 do
716
  begin
717
    if Page.Components[i].ClassNameIs('TRaveText')
718
    then // Traduire
719
    begin
720
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
721
      then
722
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
723
      TranslateComponent(Page.Components[i]);
724
      if (Page.Components[i] as TRaveText).Name = 'TextMSUnit'
725
      then
726
        with FormOptions do
727
          (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxProximal.Items[Proximal]]);
728
      if (Page.Components[i] as TRaveText).Name = 'TextLevelUnit'
729
      then
730
        with FormOptions do
731
          (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxIncorporation.Items[Incorporation]]);
732
      if (Page.Components[i] as TRaveText).Name = 'TextPhytase'
733
      then
734
        with DataModuleDeclaration do
735
          if ClientDataSetFeedsPhytaseId.IsNull
736
          then
737
            (Page.Components[i] as TRaveText).Text := ''
738
          else
739
            (Page.Components[i] as TRaveText).Text := Format('%s %1.2f', [(Page.Components[i] as TRaveText).Text, ClientDataSetFeedsPhytaseType.Value]);
740
    end;
741
    if Page.Components[i].ClassNameIs('TRaveDataText') and (Screen.Fonts.IndexOf('Arial Unicode MS') <> -1)
742
    then
743
      (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
744
  end;
745
end;
746
747
procedure TFormFeedDetail.EditEmpty(Edit: TJvValidateEdit);
748
begin
749
  Edit.DisplayFormat := dfNone;
750
  Edit.Value := '';
751
end;
752
753
procedure TFormFeedDetail.FormCreate(Sender: TObject);
754
var
755
  ProximalUnit, EnergyUnit, AAUnit, MineralsUnit: String;
756
begin
757
  if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
758
  then
759
    Font.Name := 'Arial Unicode MS';
760
//  PanelButtons.Font.Size := PanelButtons.Font.Size + 2;
761
  PanelButtons.Font.Style := [fsBold];
762
  LabelName.Font.Style := [fsBold];
763
  DBEditName.Font.Style := [fsBold];
764
  TranslateComponent(Self);
765
  with FormOptions do
766
    if Expression = 0
767
    then // sur frais
768
    begin
769
      ProximalUnit := ComboBoxProximal.Items[Proximal];
770
      EnergyUnit := ComboBoxEnergy.Items[Energy];
771
      AAUnit := ComboBoxAA.Items[AA];
772
      MineralsUnit := ComboBoxMinerals.Items[Minerals];
773
    end
774
    else // sur mati?re s?che
775
    begin
776
      ProximalUnit := Format('%s %s', [ComboBoxProximal.Items[Proximal], _('DM')]);
777
      EnergyUnit := Format('%s %s', [ComboBoxEnergy.Items[Energy], _('DM')]);
778
      AAUnit := Format('%s %s', [ComboBoxAA.Items[AA], _('DM')]);
779
      MineralsUnit := Format('%s %s', [ComboBoxMinerals.Items[Minerals], _('DM')]);
780
    end;
781
  with FormOptions do
782
    LabelMS.Caption := Format('%s (%s)', [LabelMS.Caption, ComboBoxProximal.Items[Proximal]]);
783
  GroupBoxProximal.Caption := Format('%s (%s)', [GroupBoxProximal.Caption, ProximalUnit]);
784
  GroupBoxEnergy.Caption := Format('%s (%s)', [GroupBoxEnergy.Caption, EnergyUnit]);
785
  LabelRatio.Caption := Format('%s (%%)', [LabelRatio.Caption]);
786
  GroupBoxEnergyUtilization.Caption := Format('%s (%%)', [GroupBoxEnergyUtilization.Caption]);
787 3 avalancogn
  GroupBoxMinerals.Caption := Format('%s (%s)', [GroupBoxMinerals.Caption, MineralsUnit]);
788
//  LabelCa_Pd.Caption := Format('%s (%%)', [LabelCa_Pd.Caption]);
789
  if FormOptions.Expression = 0
790
  then // sur frais
791
    LabelBE.Caption := Format('%s (%s)', [LabelBE.Caption, _('mEq/kg')])
792
  else // sur mati?re s?che
793
    LabelBE.Caption := Format('%s (%s %s)', [LabelBE.Caption, _('mEq/kg'), _('DM')]);
794 2 avalancogn
//  GroupBoxAzote.Caption := Format('%s (%%)', [GroupBoxAzote.Caption]);
795
  LabeldN.Caption := Format('%s (%%)', [LabeldN.Caption]);
796 1 avalancogn
  if FormOptions.Energy = 0
797
  then // MJ
798
    LabelLysd_EN.Caption := Format('%s (%s)', [LabelLysd_EN.Caption, _('g/MJ')])
799
  else // kcal
800
    LabelLysd_EN.Caption := Format('%s (%s)', [LabelLysd_EN.Caption, _('g/1000kcal')]);
801
  if FormOptions.Energy = 0
802
  then // MJ
803
    LabelPd_EN.Caption := Format('%s (%s)', [LabelPd_EN.Caption, _('g/MJ')])
804
  else // kcal
805
    LabelPd_EN.Caption := Format('%s (%s)', [LabelPd_EN.Caption, _('g/1000kcal')]);
806 3 avalancogn
  GroupBoxAA.Caption := Format('%s (%s)', [GroupBoxAA.Caption, AAUnit]);
807
  LabelIdealProtein.Caption := Format('%s (%%)', [LabelIdealProtein.Caption]);
808 1 avalancogn
end;
809
810
procedure TFormFeedDetail.FormShow(Sender: TObject);
811
begin
812
  with DataModuleDeclaration do
813
  begin
814
    if ClientDataSetFeedsPresentation.Value = 0
815
    then
816
      EditPresentation.Text := _('Mash')
817
    else
818
      EditPresentation.Text := _('Pellet');
819
    if ClientDataSetFeedsEB.IsNull
820
    then
821
      EditEmpty(ValidateEditEBt_EBc)
822
    else
823
      ValidateEditEBt_EBc.Value := 100;
824
    if ClientDataSetFeedsLysd.IsNull
825
    then
826
      EditEmpty(ValidateEditLysd_Lysd)
827
    else
828
      ValidateEditLysd_Lysd.Value := 100;
829
  end;
830
end;
831
832
end.