Statistiques
| Révision:

root / UnitFeedDetail.pas @ 1

Historique | Voir | Annoter | Télécharger (30,858 ko)

1
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
    LabelCrois3: TLabel;
189
    LabelTruie3: TLabel;
190
    LabelMAT: TLabel;
191
    LabelCB: TLabel;
192
    LabelMG: TLabel;
193
    LabelMM: TLabel;
194
    LabelNDF: TLabel;
195
    LabelADF: TLabel;
196
    LabelADL: TLabel;
197
    LabelAmidon: TLabel;
198
    LabelSucres: TLabel;
199
    EditPresentation: TEdit;
200
    JvImgBtnClose: TJvImgBtn;
201
    JvImgBtnHelp: TJvImgBtn;
202
    JvImgBtnXML: TJvImgBtn;
203
    JvImgBtnPrint: TJvImgBtn;
204
    JvImgBtnDelete: TJvImgBtn;
205
    JvImgBtnModify: TJvImgBtn;
206
    JvImgBtnGraphs: TJvImgBtn;
207
    PanelHead: TPanel;
208
    procedure FormCreate(Sender: TObject);
209
    procedure FormShow(Sender: TObject);
210
    procedure ActionModifyExecute(Sender: TObject);
211
    procedure ActionDeleteExecute(Sender: TObject);
212
    procedure ActionGraphsExecute(Sender: TObject);
213
    procedure ActionPrintExecute(Sender: TObject);
214
    procedure ActionXMLExecute(Sender: TObject);
215
    procedure ActionHelpExecute(Sender: TObject);
216
    procedure ActionCloseExecute(Sender: TObject);
217
  private
218
    { D?clarations priv?es }
219
    procedure BuildReport;
220
    procedure EditEmpty(Edit: TJvValidateEdit);
221
  public
222
    { D?clarations publiques }
223
  end;
224

    
225
var
226
  FormFeedDetail: TFormFeedDetail;
227

    
228
implementation
229

    
230
uses
231
  UnitDeclaration, UnitOptions, UnitFeedEdition, UnitFeedCharts;
232

    
233
{$R *.dfm}
234

    
235
procedure TFormFeedDetail.ActionCloseExecute(Sender: TObject);
236
begin
237
  ModalResult := mrClose;
238
end;
239

    
240
procedure TFormFeedDetail.ActionXMLExecute(Sender: TObject);
241
var
242
  i: Integer;
243
  USFormatSettings: TFormatSettings;
244
  XMLDoc: IXMLDocument;
245
  Workbook, Worksheet, Table, Row: IXMLNode;
246

    
247
  procedure CellData(Row: IXMLNode; Value, Format: string);
248
  var
249
    Cell, Data: IXMLNode;
250
  begin
251
    Cell := Row.AddChild('Cell');
252
    Data := Cell.AddChild('Data');
253
    Data.Attributes['ss:Type'] := Format;
254
    Data.Text := Value;
255
  end;
256

    
257
begin
258
  if SaveDialogExport.Execute
259
  then
260
  begin
261
    GetLocaleFormatSettings(1033, USFormatSettings);
262
    XMLDoc := TXMLDocument.Create(nil);
263
    try
264
      XMLDoc.XML.Clear;
265
      XMLDoc.XML.Add('<?xml version="1.0" encoding="UTF-8" ?>');
266
      XMLDoc.XML.Add('<?mso-application progid="Excel.Sheet"?>');
267
      XMLDoc.XML.Add('<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet">');
268
      XMLDoc.XML.Add('</Workbook>');
269
      XMLDoc.Active := True;
270
      Workbook := XMLDoc.DocumentElement;
271
      Workbook.DeclareNamespace('o', 'urn:schemas-microsoft-com:office:office');
272
      Workbook.DeclareNamespace('x', 'urn:schemas-microsoft-com:office:excel');
273
      Workbook.DeclareNamespace('ss', 'urn:schemas-microsoft-com:office:spreadsheet');
274
      Workbook.DeclareNamespace('html', 'http://www.w3.org/TR/REC-html40');
275
      Worksheet := Workbook.AddChild('Worksheet');
276
      Worksheet.SetAttributeNS('ss:Name', Workbook.FindNamespaceURI('ss'), Caption);
277
      Table := Worksheet.AddChild('Table');
278
      // Titre
279
      Row := Table.AddChild('Row');
280
      CellData(Row, _('Label'), 'String');
281
      CellData(Row, _('Value'), 'String');
282
      CellData(Row, _('Unit'), 'String');
283
      // Donn?es
284
      with DataModuleDeclaration do
285
        for i := 0 to ClientDataSetFeeds.FieldCount - 1 do
286
          if not (i in [0, 2, 7, 102..104, 106..109])
287
          then // Champs export?s
288
          begin
289
            Row := Table.AddChild('Row');
290
            // Label
291
            CellData(Row, _(ClientDataSetFeeds.Fields[i].DisplayLabel), 'String');
292
            // Value
293
            case i of
294
              1:
295
                CellData(Row, ClientDataSetFeeds.Fields[i].AsWideString, 'String');
296
              3: // Pr?sentation
297
                if ClientDataSetFeedsPresentation.Value = 0
298
                then
299
                  CellData(Row, _('Mash'), 'String')
300
                else
301
                  CellData(Row, _('Pellet'), 'String');
302
              6, 8..16:
303
                if not ClientDataSetFeeds.Fields[i].IsNull
304
                then
305
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number')
306
                else
307
                  CellData(Row, '', 'String');
308
              17, 19, 21, 23, 25, 27, 29:
309
                if not ClientDataSetFeeds.Fields[i].IsNull
310
                then
311
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, FormOptions.EnergyDecimals, USFormatSettings), 'Number')
312
                else
313
                  CellData(Row, '', 'String');
314
              4, 5, 18, 20, 22, 24, 26, 28, 30..34, 99:
315
                if not ClientDataSetFeeds.Fields[i].IsNull
316
                then
317
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, 1, USFormatSettings), 'Number')
318
                else
319
                  CellData(Row, '', 'String');
320
              35..54, 55..74:
321
                if not ClientDataSetFeeds.Fields[i].IsNull
322
                then
323
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, FormOptions.AADecimals, USFormatSettings), 'Number')
324
                else
325
                  CellData(Row, '', 'String');
326
              75..76, 100..101:
327
                if not ClientDataSetFeeds.Fields[i].IsNull
328
                then
329
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, 2, USFormatSettings), 'Number')
330
                else
331
                  CellData(Row, '', 'String');
332
              77..95, 105:
333
                if not ClientDataSetFeeds.Fields[i].IsNull
334
                then
335
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, 0, USFormatSettings), 'Number')
336
                else
337
                  CellData(Row, '', 'String');
338
              96..98:
339
                if not ClientDataSetFeeds.Fields[i].IsNull
340
                then
341
                  CellData(Row, FloatToStrF(ClientDataSetFeeds.Fields[i].AsFloat, ffFixed, 15, FormOptions.MineralsDecimals, USFormatSettings), 'Number')
342
                else
343
                  CellData(Row, '', 'String');
344
            end;
345
            // Unit
346
            case i of
347
              6: // MS
348
                CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String');
349
              8..16: // Analyse proximale
350
                if FormOptions.Expression = 0
351
                then // sur frais
352
                  CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String')
353
                else // sur mati?re s?che
354
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], _('DM')]), 'String');
355
              17, 19, 21, 23, 25, 27, 29: // Energie
356
                if FormOptions.Expression = 0
357
                then // sur frais
358
                  CellData(Row, FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], 'String')
359
                else // sur mati?re s?che
360
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxEnergy.Items[FormOptions.Energy], _('DM')]), 'String');
361
              4..5, 18, 20, 22, 24, 26, 28, 30..34, 77..95: // %
362
                CellData(Row, '%', 'String');
363
              35..54, 55..74: // AA
364
                if FormOptions.Expression = 0
365
                then // sur frais
366
                  CellData(Row, FormOptions.ComboBoxAA.Items[FormOptions.AA], 'String')
367
                else // sur mati?re s?che
368
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxAA.Items[FormOptions.AA], _('DM')]), 'String');
369
              75..76, 100..101: // Lysd/EN ou Pd/EN
370
                if FormOptions.Energy = 0
371
                then // MJ
372
                  CellData(Row, _('g/MJ'), 'String')
373
                else // kcal
374
                  CellData(Row, _('g/1000kcal'), 'String');
375
              96..98: // Min?raux
376
                if FormOptions.Expression = 0
377
                then // sur frais
378
                  CellData(Row, FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], 'String')
379
                else // sur mati?re s?che
380
                  CellData(Row, Format('%s %s', [FormOptions.ComboBoxMinerals.Items[FormOptions.Minerals], _('DM')]), 'String');
381
              105:
382
                CellData(Row, _('IU/kg'), 'String');
383
            end;
384
          end;
385
      Worksheet := Workbook.AddChild('Worksheet');
386
      Worksheet.SetAttributeNS('ss:Name', Workbook.FindNamespaceURI('ss'), _('Ingredients'));
387
      Table := Worksheet.AddChild('Table');
388
      with DataModuleDeclaration do
389
      begin
390
        // Titres
391
        Row := Table.AddChild('Row');
392
        CellData(Row, _('Diet'), 'String');
393
        CellData(Row, ClientDataSetFeedsName.Value, 'String');
394
        Row := Table.AddChild('Row');
395
        Row := Table.AddChild('Row');
396
        CellData(Row, _('Ingredient'), 'String');
397
        CellData(Row, _('Dry matter'), 'String');
398
        CellData(Row, _('Incorporation level'), 'String');
399
        Row := Table.AddChild('Row');
400
        CellData(Row, '', 'String');
401
        CellData(Row, FormOptions.ComboBoxProximal.Items[FormOptions.Proximal], 'String');
402
        CellData(Row, FormOptions.ComboBoxIncorporation.Items[FormOptions.Incorporation], 'String');
403
        // Donn?es
404
        ClientDataSetComposition.Filter := Format('Feed = %d', [ClientDataSetFeedsId.Value]);
405
        ClientDataSetComposition.Filtered := True;
406
        ClientDataSetComposition.First;
407
        while not ClientDataSetComposition.Eof do
408
        begin
409
          Row := Table.AddChild('Row');
410
          CellData(Row, ClientDataSetCompositionIngredientName.Value, 'String');
411
          CellData(Row, FloatToStrF(ClientDataSetCompositionMS.AsFloat, ffFixed, 15, FormOptions.ProximalDecimals, USFormatSettings), 'Number');
412
          CellData(Row, FloatToStrF(ClientDataSetCompositionLevel.AsFloat, ffFixed, 15, FormOptions.IncorporationDecimals, USFormatSettings), 'Number');
413
          ClientDataSetComposition.Next;
414
        end;
415
        ClientDataSetComposition.Filtered := False;
416
        ClientDataSetComposition.Filter := '';
417
        if not ClientDataSetFeedsPhytaseId.IsNull
418
        then // Phytase
419
        begin
420
          Row := Table.AddChild('Row');
421
          CellData(Row, Format('%s %1.2f', [_('Phytase'), ClientDataSetFeedsPhytaseType.Value]), 'String');
422
          CellData(Row, '', 'String');
423
          CellData(Row, FloatToStrF(ClientDataSetFeedsPhytaseLevel.AsFloat, ffFixed, 15, FormOptions.IncorporationDecimals, USFormatSettings), 'Number');
424
        end;
425
      end;
426
      XMLDoc.SaveToFile(SaveDialogExport.FileName);
427
      XmlDoc.Active := False;
428
    finally
429
      XMLDoc := nil;
430
    end;
431
  end;
432
end;
433

    
434
procedure TFormFeedDetail.ActionDeleteExecute(Sender: TObject);
435
var
436
  FeedName: String;
437
begin
438
  with DataModuleDeclaration do
439
    if MessageDlg(_('Are sure you want to delete this record?') + sLineBreak + _('This action could not be canceled.'), mtConfirmation, [mbYes, mbNo], 0) = mrYes
440
    then
441
    begin
442
      ClientDataSetFeeds.DisableControls;
443
      try
444
        FeedName := ClientDataSetFeedsName.Value;
445
        // Supprimer la composition du r?gime
446
        DBUser.BeginTransaction;
447
        try
448
          DBUser.ExecSQL('DELETE FROM Composition '
449
            + Format('WHERE Feed = %d', [ClientDataSetFeedsId.Value]));
450
          DBUser.Commit;
451
        except
452
          DBUser.RollBack;
453
          MessageDlg(Format(_('Unknown error: %s %s %s'), ['UnitFeedDetail', 'ActionDeleteExecute', 'DBUser (DELETE FROM Composition)']), mtError, [mbOK], 0);
454
          Exit;
455
        end;
456
        // Suprimer de ClientDataSetComposition
457
        ClientDataSetComposition.Filter := Format('Feed = %d', [ClientDataSetFeedsId.Value]);
458
        ClientDataSetComposition.Filtered := True;
459
        ClientDataSetComposition.First;
460
        while not ClientDataSetComposition.Eof do
461
          ClientDataSetComposition.Delete;
462
        ClientDataSetComposition.Filtered := False;
463
        ClientDataSetComposition.Filter := '';
464
        // Suprimer l'aliment
465
        DBUser.BeginTransaction;
466
        try
467
          DBUser.ExecSQL('DELETE FROM Feeds '
468
            + Format('WHERE Id = %d', [ClientDataSetFeedsId.Value]));
469
          DBUser.Commit;
470
        except
471
          DBUser.RollBack;
472
          MessageDlg(Format(_('Unknown error: %s %s %s'), ['UnitFeedDetail', 'ActionDeleteExecute', 'DBUser (DELETE FROM Feeds)']), mtError, [mbOK], 0);
473
          Exit;
474
        end;
475
        // Suprimer de ClientDataSetFeeds
476
        ClientDataSetFeeds.Delete;
477
        // Suprimer le nom de la liste des r?gimes
478
        FeedList.Delete(FeedList.IndexOf(FeedName));
479
        // Fermer la fen?tre
480
        Close;
481
      finally
482
        ClientDataSetFeeds.EnableControls;
483
      end;
484
    end;
485
end;
486

    
487
procedure TFormFeedDetail.ActionGraphsExecute(Sender: TObject);
488
begin
489
  FormFeedCharts := TFormFeedCharts.Create(nil);
490
  try
491
    FormFeedCharts.ShowModal;
492
  finally
493
    FormFeedCharts.Release;
494
  end;
495
end;
496

    
497
procedure TFormFeedDetail.ActionHelpExecute(Sender: TObject);
498
begin
499
  Application.HelpContext(HelpContext);
500
end;
501

    
502
procedure TFormFeedDetail.ActionModifyExecute(Sender: TObject);
503
begin
504
  FormFeedEdition := TFormFeedEdition.Create(nil);
505
  try
506
    FormFeedEdition.ShowModal;
507
  finally
508
    FormFeedEdition.Release;
509
  end;
510
//  with DataModuleDeclaration do
511
//    Hint := ClientDataSetFeedsDescription.Value;
512
end;
513

    
514
procedure TFormFeedDetail.ActionPrintExecute(Sender: TObject);
515
begin
516
  if RpDev.PrinterSetupDialog
517
  then
518
  begin
519
    RvSystemReport.DoNativeOutput := false;
520
    RvSystemReport.DefaultDest := rdPrinter;
521
    RvSystemReport.RenderObject := nil;
522
    RvSystemReport.OutputFileName := '';
523
    RvProjectReport.Open;
524
    BuildReport;
525
    RvProjectReport.Execute;
526
    RvProjectReport.Close;
527
    with DataModuleDeclaration do
528
    begin
529
      ClientDataSetComposition.Filtered := False;
530
      ClientDataSetComposition.Filter := '';
531
    end;
532
  end;
533
end;
534

    
535
procedure TFormFeedDetail.BuildReport;
536
var
537
  i: Integer;
538
  Page: TRavePage;
539
begin
540
  with DataModuleDeclaration do
541
  begin
542
    if ClientDataSetFeeds.Eof
543
    then // Bug : seconde page blanche
544
      if ClientDataSetIngredients.RecordCount > 1
545
      then
546
      begin
547
        ClientDataSetIngredients.Prior;
548
        ClientDataSetIngredients.Next;
549
      end
550
      else
551
        ClientDataSetIngredients.First;
552
    ClientDataSetComposition.Filter := Format('Feed = %d', [ClientDataSetFeedsId.Value]);
553
    ClientDataSetComposition.Filtered := True;
554
    // Taux d'incorporation total
555
    ClientDataSetFeeds.Edit;
556
    if ClientDataSetComposition.Aggregates[0].Value = Null
557
    then
558
      ClientDataSetFeedsLevelSum.Clear
559
    else
560
      ClientDataSetFeedsLevelSum.Value := ClientDataSetComposition.Aggregates[0].Value;
561
    ClientDataSetFeeds.Post;
562
  end;
563
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportFeed.PageFeed1', nil) as TRavePage;
564
  for i := 0 to Page.ComponentCount - 1 do
565
  begin
566
    if Page.Components[i].ClassNameIs('TRaveText')
567
    then // Traduire
568
    begin
569
      if (Page.Components[i] as TRaveText).Name = 'TextPresentation2'
570
      then
571
        if DataModuleDeclaration.ClientDataSetFeedsPresentation.Value = 0
572
        then
573
          (Page.Components[i] as TRaveText).Text := 'Mash'
574
        else
575
          (Page.Components[i] as TRaveText).Text := 'Pellet';
576
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
577
      then
578
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
579
      TranslateComponent(Page.Components[i]);
580
      if (Page.Components[i] as TRaveText).Name = 'TextMS'
581
      then
582
        with FormOptions do
583
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, ComboBoxProximal.Items[Proximal]]);
584
      if (Page.Components[i] as TRaveText).Name = 'TextUnitProximal'
585
      then
586
        with FormOptions do
587
          if Expression = 0
588
          then // sur frais
589
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxProximal.Items[Proximal]])
590
          else // sur mati?re s?che
591
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxProximal.Items[Proximal], _('DM')]);
592
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyC'
593
      then
594
        with FormOptions do
595
          if Expression = 0
596
          then // sur frais
597
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxEnergy.Items[Energy]])
598
          else // sur mati?re s?che
599
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxEnergy.Items[Energy], _('DM')]);
600
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyT'
601
      then
602
        with FormOptions do
603
          if Expression = 0
604
          then // sur frais
605
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxEnergy.Items[Energy]])
606
          else // sur mati?re s?che
607
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxEnergy.Items[Energy], _('DM')]);
608
      if (Page.Components[i] as TRaveText).Name = 'TextUnitEnergyRatio'
609
      then
610
        (Page.Components[i] as TRaveText).Text := '(%)';
611
      if (Page.Components[i] as TRaveText).Name = 'TextEBt_EBc'
612
      then
613
        (Page.Components[i] as TRaveText).Text := ValidateEditEBt_EBc.Text;
614
      if (Page.Components[i] as TRaveText).Name = 'TextBonus'
615
      then
616
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
617
      if (Page.Components[i] as TRaveText).Name = 'TextdE'
618
      then
619
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
620
      if (Page.Components[i] as TRaveText).Name = 'TextEM_ED'
621
      then
622
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
623
      if (Page.Components[i] as TRaveText).Name = 'TextEN_EM'
624
      then
625
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
626
    end;
627
    if Page.Components[i].ClassNameIs('TRaveDataMemo') and (Screen.Fonts.IndexOf('Arial Unicode MS') <> -1)
628
    then
629
      (Page.Components[i] as TRaveDataMemo).Font.Name := 'Arial Unicode MS';
630
    if Page.Components[i].ClassNameIs('TRaveDataText') and (Screen.Fonts.IndexOf('Arial Unicode MS') <> -1)
631
    then
632
      (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
633
  end;
634
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportFeed.PageFeed2', nil) as TRavePage;
635
  for i := 0 to Page.ComponentCount - 1 do
636
  begin
637
    if Page.Components[i].ClassNameIs('TRaveText')
638
    then // Traduire
639
    begin
640
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
641
      then
642
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
643
      TranslateComponent(Page.Components[i]);
644
      if (Page.Components[i] as TRaveText).Name = 'TextdN'
645
      then
646
        (Page.Components[i] as TRaveText).Text := Format('%s (%%)', [(Page.Components[i] as TRaveText).Text]);
647
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAATot'
648
      then
649
        with FormOptions do
650
          if Expression = 0
651
          then // sur frais
652
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxAA.Items[AA]])
653
          else // sur mati?re s?che
654
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxAA.Items[AA], _('DM')]);
655
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAADig'
656
      then
657
        with FormOptions do
658
          if Expression = 0
659
          then // sur frais
660
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxAA.Items[AA]])
661
          else // sur mati?re s?che
662
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxAA.Items[AA], _('DM')]);
663
      if (Page.Components[i] as TRaveText).Name = 'TextUnitAAProtId'
664
      then
665
        (Page.Components[i] as TRaveText).Text := '(%)';
666
      if (Page.Components[i] as TRaveText).Name = 'TextLysd_Lysd'
667
      then
668
        (Page.Components[i] as TRaveText).Text := ValidateEditLysd_Lysd.Text;
669
      if (Page.Components[i] as TRaveText).Name = 'TextUnitLysd_EN'
670
      then
671
        if FormOptions.Energy = 0
672
        then // MJ
673
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/MJ')])
674
        else // kcal
675
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/1000kcal')]);
676
      if (Page.Components[i] as TRaveText).Name = 'TextUnitMinerals'
677
      then
678
        with FormOptions do
679
          if Expression = 0
680
          then // sur frais
681
            (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxMinerals.Items[Minerals]])
682
          else // sur mati?re s?che
683
            (Page.Components[i] as TRaveText).Text := Format('(%s %s)', [ComboBoxMinerals.Items[Minerals], _('DM')]);
684
      if (Page.Components[i] as TRaveText).Name = 'TextUnitPd_EN'
685
      then
686
        if FormOptions.Energy = 0
687
        then // MJ
688
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/MJ')])
689
        else // kcal
690
          (Page.Components[i] as TRaveText).Text := Format('%s (%s)', [(Page.Components[i] as TRaveText).Text, _('g/1000kcal')]);
691
    end;
692
    if Page.Components[i].ClassNameIs('TRaveDataText') and (Screen.Fonts.IndexOf('Arial Unicode MS') <> -1)
693
    then
694
      (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
695
  end;
696
  Page := RvProjectReport.ProjMan.FindRaveComponent('ReportFeed.PageComposition', nil) as TRavePage;
697
  for i := 0 to Page.ComponentCount - 1 do
698
  begin
699
    if Page.Components[i].ClassNameIs('TRaveText')
700
    then // Traduire
701
    begin
702
      if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
703
      then
704
        (Page.Components[i] as TRaveText).Font.Name := 'Arial Unicode MS';
705
      TranslateComponent(Page.Components[i]);
706
      if (Page.Components[i] as TRaveText).Name = 'TextMSUnit'
707
      then
708
        with FormOptions do
709
          (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxProximal.Items[Proximal]]);
710
      if (Page.Components[i] as TRaveText).Name = 'TextLevelUnit'
711
      then
712
        with FormOptions do
713
          (Page.Components[i] as TRaveText).Text := Format('(%s)', [ComboBoxIncorporation.Items[Incorporation]]);
714
      if (Page.Components[i] as TRaveText).Name = 'TextPhytase'
715
      then
716
        with DataModuleDeclaration do
717
          if ClientDataSetFeedsPhytaseId.IsNull
718
          then
719
            (Page.Components[i] as TRaveText).Text := ''
720
          else
721
            (Page.Components[i] as TRaveText).Text := Format('%s %1.2f', [(Page.Components[i] as TRaveText).Text, ClientDataSetFeedsPhytaseType.Value]);
722
    end;
723
    if Page.Components[i].ClassNameIs('TRaveDataText') and (Screen.Fonts.IndexOf('Arial Unicode MS') <> -1)
724
    then
725
      (Page.Components[i] as TRaveDataText).Font.Name := 'Arial Unicode MS';
726
  end;
727
end;
728

    
729
procedure TFormFeedDetail.EditEmpty(Edit: TJvValidateEdit);
730
begin
731
  Edit.DisplayFormat := dfNone;
732
  Edit.Value := '';
733
end;
734

    
735
procedure TFormFeedDetail.FormCreate(Sender: TObject);
736
var
737
  ProximalUnit, EnergyUnit, AAUnit, MineralsUnit: String;
738
begin
739
  if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1
740
  then
741
    Font.Name := 'Arial Unicode MS';
742
//  PanelButtons.Font.Size := PanelButtons.Font.Size + 2;
743
  PanelButtons.Font.Style := [fsBold];
744
  LabelName.Font.Style := [fsBold];
745
  DBEditName.Font.Style := [fsBold];
746
  TranslateComponent(Self);
747
  with FormOptions do
748
    if Expression = 0
749
    then // sur frais
750
    begin
751
      ProximalUnit := ComboBoxProximal.Items[Proximal];
752
      EnergyUnit := ComboBoxEnergy.Items[Energy];
753
      AAUnit := ComboBoxAA.Items[AA];
754
      MineralsUnit := ComboBoxMinerals.Items[Minerals];
755
    end
756
    else // sur mati?re s?che
757
    begin
758
      ProximalUnit := Format('%s %s', [ComboBoxProximal.Items[Proximal], _('DM')]);
759
      EnergyUnit := Format('%s %s', [ComboBoxEnergy.Items[Energy], _('DM')]);
760
      AAUnit := Format('%s %s', [ComboBoxAA.Items[AA], _('DM')]);
761
      MineralsUnit := Format('%s %s', [ComboBoxMinerals.Items[Minerals], _('DM')]);
762
    end;
763
  with FormOptions do
764
    LabelMS.Caption := Format('%s (%s)', [LabelMS.Caption, ComboBoxProximal.Items[Proximal]]);
765
  GroupBoxProximal.Caption := Format('%s (%s)', [GroupBoxProximal.Caption, ProximalUnit]);
766
  GroupBoxEnergy.Caption := Format('%s (%s)', [GroupBoxEnergy.Caption, EnergyUnit]);
767
  LabelRatio.Caption := Format('%s (%%)', [LabelRatio.Caption]);
768
  GroupBoxEnergyUtilization.Caption := Format('%s (%%)', [GroupBoxEnergyUtilization.Caption]);
769
  GroupBoxAzote.Caption := Format('%s (%%)', [GroupBoxAzote.Caption]);
770
  if FormOptions.Energy = 0
771
  then // MJ
772
    LabelLysd_EN.Caption := Format('%s (%s)', [LabelLysd_EN.Caption, _('g/MJ')])
773
  else // kcal
774
    LabelLysd_EN.Caption := Format('%s (%s)', [LabelLysd_EN.Caption, _('g/1000kcal')]);
775
  GroupBoxAA.Caption := Format('%s (%s)', [GroupBoxAA.Caption, AAUnit]);
776
  LabelIdealProtein.Caption := Format('%s (%%)', [LabelIdealProtein.Caption]);
777
  GroupBoxMinerals.Caption := Format('%s (%s)', [GroupBoxMinerals.Caption, MineralsUnit]);
778
//  LabelCa_Pd.Caption := Format('%s (%%)', [LabelCa_Pd.Caption]);
779
  if FormOptions.Energy = 0
780
  then // MJ
781
    LabelPd_EN.Caption := Format('%s (%s)', [LabelPd_EN.Caption, _('g/MJ')])
782
  else // kcal
783
    LabelPd_EN.Caption := Format('%s (%s)', [LabelPd_EN.Caption, _('g/1000kcal')]);
784
end;
785

    
786
procedure TFormFeedDetail.FormShow(Sender: TObject);
787
begin
788
  with DataModuleDeclaration do
789
  begin
790
    if ClientDataSetFeedsPresentation.Value = 0
791
    then
792
      EditPresentation.Text := _('Mash')
793
    else
794
      EditPresentation.Text := _('Pellet');
795
    if ClientDataSetFeedsEB.IsNull
796
    then
797
      EditEmpty(ValidateEditEBt_EBc)
798
    else
799
      ValidateEditEBt_EBc.Value := 100;
800
    if ClientDataSetFeedsLysd.IsNull
801
    then
802
      EditEmpty(ValidateEditLysd_Lysd)
803
    else
804
      ValidateEditLysd_Lysd.Value := 100;
805
  end;
806
end;
807

    
808
end.