root / UFResBesLactE.pas @ 5
Historique | Voir | Annoter | Télécharger (13,213 ko)
1 |
unit UFResBesLactE;
|
---|---|
2 |
|
3 |
interface
|
4 |
|
5 |
uses
|
6 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
7 |
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, CheckLst, Menus, Printers, |
8 |
Math, Contnrs, PBNumEdit, PBSuperSpin, Grids, TeEngine, Series, TeeProcs, |
9 |
Chart, TeeEdit, UVariables, gnugettext; |
10 |
|
11 |
type
|
12 |
TFResBesLactE = class(TForm)
|
13 |
PC: TPageControl; |
14 |
TabNRJ: TTabSheet; |
15 |
TabAA: TTabSheet; |
16 |
CBAA3: TComboBox; |
17 |
CBAA4: TComboBox; |
18 |
GBAAY: TGroupBox; |
19 |
Graph: TChart; |
20 |
GBNRJY: TGroupBox; |
21 |
CBNRJ3: TComboBox; |
22 |
LBAA: TListBox; |
23 |
LBNRJ: TListBox; |
24 |
TSAli: TTabSheet; |
25 |
TSMin: TTabSheet; |
26 |
GBMin: TGroupBox; |
27 |
CBMin3: TComboBox; |
28 |
CBMin4: TComboBox; |
29 |
CBNRJ4: TComboBox; |
30 |
PM: TPopupMenu; |
31 |
MI3D: TMenuItem; |
32 |
MIPreview: TMenuItem; |
33 |
MIPrint: TMenuItem; |
34 |
PD: TPrintDialog; |
35 |
procedure FormClose(Sender: TObject; var Action: TCloseAction); |
36 |
procedure FormShow(Sender: TObject);
|
37 |
procedure PCChange(Sender: TObject);
|
38 |
procedure CBNRJ3Change(Sender: TObject);
|
39 |
procedure CBNRJ4Change(Sender: TObject);
|
40 |
procedure CBAA3Change(Sender: TObject);
|
41 |
procedure CBAA4Change(Sender: TObject);
|
42 |
procedure CBAli2Change(Sender: TObject);
|
43 |
procedure CBMin3Change(Sender: TObject);
|
44 |
procedure CBMin4Change(Sender: TObject);
|
45 |
procedure MI3DClick(Sender: TObject);
|
46 |
procedure MIPreviewClick(Sender: TObject);
|
47 |
procedure MIPrintClick(Sender: TObject);
|
48 |
procedure FormCreate(Sender: TObject);
|
49 |
procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND; |
50 |
private
|
51 |
{ D?clarations priv?es }
|
52 |
BarAli : TBarSeries ; |
53 |
ListNRJ : TStrings ; |
54 |
BarNRJ : array of TBarSeries ; |
55 |
ListAA : TStrings ; |
56 |
BarAA : array of TBarSeries ; |
57 |
BarMin : TBarSeries ; |
58 |
procedure ResetGraph ;
|
59 |
procedure InitAli ;
|
60 |
procedure AffGraphAli ;
|
61 |
procedure InitNRJ ;
|
62 |
procedure AffGraphNRJ ;
|
63 |
procedure InitAA ;
|
64 |
procedure AffGraphAA ;
|
65 |
procedure InitMin ;
|
66 |
procedure AffGraphMin ;
|
67 |
public
|
68 |
{ D?clarations publiques }
|
69 |
end;
|
70 |
|
71 |
var
|
72 |
FResBesLactE: TFResBesLactE; |
73 |
|
74 |
implementation
|
75 |
|
76 |
uses
|
77 |
UStrings, UFindRec, UUtil, UEchelle, UFBesLactE, UFPrevGraph ; |
78 |
|
79 |
{$R *.dfm}
|
80 |
|
81 |
{ TFResBesLactE }
|
82 |
|
83 |
procedure TFResBesLactE.FormCreate(Sender: TObject);
|
84 |
begin
|
85 |
if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1 |
86 |
then
|
87 |
Font.Name := 'Arial Unicode MS';
|
88 |
TranslateComponent(Self); |
89 |
Constraints.MinWidth := 544 + (Width - ClientWidth);
|
90 |
Width := 640;
|
91 |
Constraints.MinHeight := 400 + (Height - ClientHeight);
|
92 |
Height := 480;
|
93 |
CBNRJ3.ItemIndex := 0;
|
94 |
CBNRJ4.Items.Add(Format('%s/%s', [StrMJ, StrJ]));
|
95 |
CBNRJ4.Items.Add('%');
|
96 |
CBNRJ4.ItemIndex := 0;
|
97 |
CBAA3.ItemIndex := 0;
|
98 |
CBAA4.Items.Add(Format('%s/%s', [StrG, StrJ]));
|
99 |
CBAA4.Items.Add('%');
|
100 |
CBAA4.Items.Add(Format('%s/%s %s', [StrG, StrKg, StrAlimentUnit]));
|
101 |
CBAA4.ItemIndex := 0;
|
102 |
CBMin3.ItemIndex := 0;
|
103 |
CBMin4.Items.Add(Format('%s/%s', [StrG, StrJ]));
|
104 |
CBMin4.Items.Add(Format('%s/%s %s', [StrG, StrKg, StrAlimentUnit]));
|
105 |
CBMin4.ItemIndex := 0;
|
106 |
end;
|
107 |
|
108 |
procedure TFResBesLactE.FormShow (Sender : TObject) ;
|
109 |
begin
|
110 |
MIPrint.Enabled := IsComplete or IsEducation ;
|
111 |
// Aliment
|
112 |
InitAli ; |
113 |
// Energie
|
114 |
InitNRJ ; |
115 |
// Acides Amin?s
|
116 |
InitAA ; |
117 |
// Min?raux
|
118 |
InitMin ; |
119 |
// Affichage principal
|
120 |
PC.ActivePageIndex := 0 ;
|
121 |
PCChange (nil) ;
|
122 |
end ;
|
123 |
|
124 |
procedure TFResBesLactE.FormClose (Sender : TObject ; var Action : TCloseAction) ; |
125 |
var
|
126 |
i : integer ; |
127 |
begin
|
128 |
// Aliment
|
129 |
BarAli.Free ; |
130 |
// Energie
|
131 |
for i := 0 to ListNRJ.Count - 1 do |
132 |
BarNRJ[i].Free ; |
133 |
SetLength (BarNRJ, 0) ;
|
134 |
ListNRJ.Free ; |
135 |
// Acides Amin?s
|
136 |
for i := 0 to ListAA.Count - 1 do |
137 |
BarAA[i].Free ; |
138 |
SetLength (BarAA, 0) ;
|
139 |
ListAA.Free ; |
140 |
// Min?raux
|
141 |
BarMin.Free ; |
142 |
end ;
|
143 |
|
144 |
procedure TFResBesLactE.PCChange (Sender : TObject) ;
|
145 |
begin
|
146 |
case PC.ActivePageIndex of |
147 |
0 : // Aliment |
148 |
AffGraphAli ; |
149 |
1 : // Energie |
150 |
AffGraphNRJ ; |
151 |
2 : // Acides Amin?s |
152 |
AffGraphAA ; |
153 |
3 : // Min?raux |
154 |
AffGraphMin ; |
155 |
end ;
|
156 |
end ;
|
157 |
|
158 |
procedure TFResBesLactE.ResetGraph ;
|
159 |
var
|
160 |
i : integer ; |
161 |
begin
|
162 |
Graph.UndoZoom ; |
163 |
Graph.View3D := FALSE ; |
164 |
Graph.Legend.Visible := TRUE ; |
165 |
Graph.Title.Text.Clear ; |
166 |
Graph.SubTitle.Text.Clear ; |
167 |
Graph.LeftAxis.Automatic := FALSE ; |
168 |
Graph.BottomAxis.MinimumOffset := 0;
|
169 |
Graph.BottomAxis.MaximumOffset := 0;
|
170 |
// Aliment
|
171 |
BarAli.Active := FALSE ; |
172 |
// Energie
|
173 |
for i := 0 to ListNRJ.Count - 1 do |
174 |
BarNRJ[i].Active := FALSE ; |
175 |
// Acides Amin?s
|
176 |
for i := 0 to ListAA.Count - 1 do |
177 |
BarAA[i].Active := FALSE ; |
178 |
// Min?raux
|
179 |
BarMin.Active := FALSE ; |
180 |
end ;
|
181 |
|
182 |
procedure TFResBesLactE.MI3DClick (Sender : TObject) ;
|
183 |
begin
|
184 |
Graph.View3D := not (Graph.View3D) ;
|
185 |
end ;
|
186 |
|
187 |
procedure TFResBesLactE.MIPreviewClick (Sender : TObject) ;
|
188 |
begin
|
189 |
FPrevGraph := TFPrevGraph.Create (Self) ; |
190 |
with FPrevGraph do |
191 |
begin
|
192 |
TPPGraph.Panels.Add (Graph) ; |
193 |
ShowModal ; |
194 |
Release ; |
195 |
end ;
|
196 |
end ;
|
197 |
|
198 |
procedure TFResBesLactE.MIPrintClick (Sender : TObject) ;
|
199 |
begin
|
200 |
if PD.Execute
|
201 |
then
|
202 |
begin
|
203 |
Printer.Orientation := poLandscape ; |
204 |
Graph.Print ; |
205 |
end ;
|
206 |
end ;
|
207 |
|
208 |
/////////////////
|
209 |
// Aliment //
|
210 |
/////////////////
|
211 |
procedure TFResBesLactE.InitAli ;
|
212 |
begin
|
213 |
// BarAli : s?rie (barre) graphique
|
214 |
BarAli := TBarSeries.Create (Graph) ; |
215 |
BarAli.ParentChart := Graph ; |
216 |
BarAli.Title := ' ' ;
|
217 |
BarAli.SeriesColor := clTeal ; |
218 |
BarAli.BarPen.Color := BarAli.SeriesColor ; |
219 |
BarAli.Marks.Style := smsValue ; |
220 |
BarAli.Marks.ArrowLength := 0 ;
|
221 |
BarAli.Marks.Arrow.Visible := FALSE ; |
222 |
BarAli.Marks.Brush.Style := bsClear ; |
223 |
BarAli.Marks.Frame.Visible := FALSE ; |
224 |
BarAli.Marks.Font.Style := [fsBold] ; |
225 |
Graph.AddSeries (BarAli) ; |
226 |
end ;
|
227 |
|
228 |
procedure TFResBesLactE.AffGraphAli ;
|
229 |
var
|
230 |
j : integer ; |
231 |
|
232 |
// Ordonn?e
|
233 |
function AliY : double ;
|
234 |
begin
|
235 |
with FBesLactE do |
236 |
if (AppEMTot[j] = 0) |
237 |
then
|
238 |
result := 0
|
239 |
else
|
240 |
result := BesEMTot[j] * AppAliTot[j] / AppEMTot[j] ; |
241 |
end ;
|
242 |
|
243 |
// AffGraphAli
|
244 |
begin
|
245 |
ResetGraph ; |
246 |
Graph.Legend.Visible := FALSE ; |
247 |
Graph.Title.Text.Add (TSAli.Caption) ; |
248 |
Graph.LeftAxis.Title.Caption := Format ('%s (%s/%s)', [TSAli.Caption, StrKg, StrJ]) ;
|
249 |
Graph.BottomAxis.Title.Caption := _('Litter');
|
250 |
// Affichage de la barre
|
251 |
BarAli.Active := TRUE ; |
252 |
BarAli.Clear ; |
253 |
for j := 1 to NB_CYCLES do |
254 |
BarAli.AddBar (AliY, Format ('%d', [j]), clTeeColor) ;
|
255 |
AjustEchelle (Graph) ; |
256 |
end ;
|
257 |
|
258 |
procedure TFResBesLactE.CBAli2Change(Sender: TObject);
|
259 |
begin
|
260 |
|
261 |
end;
|
262 |
|
263 |
/////////////////
|
264 |
// Energie //
|
265 |
/////////////////
|
266 |
procedure TFResBesLactE.InitNRJ ;
|
267 |
const
|
268 |
TabColor : array[0..1] of TColor |
269 |
= (clOlive, clWhite) ; |
270 |
var
|
271 |
i : integer ; |
272 |
begin
|
273 |
// ListNRJ : liste pour l'?nergie
|
274 |
ListNRJ := TStringList.Create ; |
275 |
ListNRJ.Assign (LBNRJ.Items) ; |
276 |
// BarNRJ : s?ries (barres) graphiques
|
277 |
SetLength (BarNRJ, ListNRJ.Count) ; |
278 |
for i := 0 to ListNRJ.Count - 1 do |
279 |
begin
|
280 |
BarNRJ[i] := TBarSeries.Create (Graph) ; |
281 |
BarNRJ[i].ParentChart := Graph ; |
282 |
BarNRJ[i].Title := ListNRJ[i] ; |
283 |
BarNRJ[i].SeriesColor := TabColor[i] ; |
284 |
BarNRJ[i].BarPen.Color := BarNRJ[i].SeriesColor ; |
285 |
BarNRJ[i].Marks.Visible := FALSE ; |
286 |
Graph.AddSeries (BarNRJ[i]) ; |
287 |
end ;
|
288 |
end ;
|
289 |
|
290 |
procedure TFResBesLactE.AffGraphNRJ ;
|
291 |
var
|
292 |
i, j : integer ; |
293 |
m : double ; |
294 |
|
295 |
// Ordonn?e
|
296 |
function NRJY : double ;
|
297 |
begin
|
298 |
case i of |
299 |
0 : // Entretien |
300 |
result := FBesLactE.BesEMEntTot[j] ; |
301 |
1 : // Lait |
302 |
result := FBesLactE.BesEMLaitTot[j] ; |
303 |
else
|
304 |
result := 0 ;
|
305 |
end ;
|
306 |
end ;
|
307 |
|
308 |
// AffGraphNRJ
|
309 |
begin
|
310 |
ResetGraph ; |
311 |
Graph.Title.Text.Add (TabNRJ.Caption) ; |
312 |
Graph.LeftAxis.Title.Caption := Format ('%s (%s)', [CBNRJ3.Text, CBNRJ4.Text]) ;
|
313 |
Graph.BottomAxis.Title.Caption := _('Litter');
|
314 |
// Affichage des barres
|
315 |
for i := 0 to ListNRJ.Count - 1 do |
316 |
BarNRJ[i].Active := TRUE ; |
317 |
for i := 0 to ListNRJ.Count - 1 do |
318 |
BarNRJ[i].Clear ; |
319 |
if (CBNRJ4.ItemIndex = 1) |
320 |
then
|
321 |
for i := 0 to ListNRJ.Count - 1 do |
322 |
BarNRJ[i].MultiBar := mbStacked100 |
323 |
else
|
324 |
for i := 0 to ListNRJ.Count - 1 do |
325 |
BarNRJ[i].MultiBar := mbStacked ; |
326 |
for j := 1 to NB_CYCLES do |
327 |
begin
|
328 |
case CBNRJ3.ItemIndex of |
329 |
0 : // Energie digestible |
330 |
m := FBesLactE.AppEDTot[j] / FBesLactE.AppEMTot[j] ; |
331 |
2 : // Energie nette |
332 |
m := FBesLactE.AppENTot[j] / FBesLactE.AppEMTot[j] ; |
333 |
else
|
334 |
m := 1 ;
|
335 |
end ;
|
336 |
for i := 0 to ListNRJ.Count - 1 do |
337 |
BarNRJ[i].AddBar (NRJY * m, Format ('%d', [j]), clTeeColor) ;
|
338 |
end ;
|
339 |
AjustEchelle (Graph) ; |
340 |
end ;
|
341 |
|
342 |
procedure TFResBesLactE.CBNRJ3Change (Sender : TObject) ;
|
343 |
begin
|
344 |
AffGraphNRJ ; |
345 |
end ;
|
346 |
|
347 |
procedure TFResBesLactE.CBNRJ4Change (Sender : TObject) ;
|
348 |
begin
|
349 |
AffGraphNRJ ; |
350 |
end ;
|
351 |
|
352 |
///////////////////////
|
353 |
// Acides amin?s //
|
354 |
///////////////////////
|
355 |
procedure TFResBesLactE.InitAA ;
|
356 |
const
|
357 |
TabColor : array[0..1] of TColor |
358 |
= (clOlive, clWhite) ; |
359 |
var
|
360 |
i : integer ; |
361 |
begin
|
362 |
// ListAA : liste pour les acides amin?s
|
363 |
ListAA := TStringList.Create ; |
364 |
ListAA.Assign (LBAA.Items) ; |
365 |
// BarAA : s?ries (barres) graphiques
|
366 |
SetLength (BarAA, ListAA.Count) ; |
367 |
for i := 0 to ListAA.Count - 1 do |
368 |
begin
|
369 |
BarAA[i] := TBarSeries.Create (Graph) ; |
370 |
BarAA[i].ParentChart := Graph ; |
371 |
BarAA[i].Title := ListAA[i] ; |
372 |
BarAA[i].SeriesColor := TabColor[i] ; |
373 |
BarAA[i].BarPen.Color := BarAA[i].SeriesColor ; |
374 |
BarAA[i].Marks.Visible := FALSE ; |
375 |
Graph.AddSeries (BarAA[i]) ; |
376 |
end ;
|
377 |
end ;
|
378 |
|
379 |
procedure TFResBesLactE.AffGraphAA ;
|
380 |
var
|
381 |
h, i, j : integer ; |
382 |
|
383 |
// Ordonn?e
|
384 |
function AAY : double ;
|
385 |
var
|
386 |
a : integer ; |
387 |
d : double ; |
388 |
begin
|
389 |
case h of |
390 |
3 : // met+cys |
391 |
a := 13 ;
|
392 |
7 : // phe+tyr |
393 |
a := 14 ;
|
394 |
else
|
395 |
a := h ; |
396 |
end ;
|
397 |
// Diviseur
|
398 |
case CBAA4.ItemIndex of |
399 |
0 : // Dur?e |
400 |
d := PProfilT.DureeLact ; |
401 |
2 : // Aliment |
402 |
d := FBesLactE.AppAliTot[j] ; |
403 |
else
|
404 |
d := 1 ;
|
405 |
end ;
|
406 |
case i of |
407 |
0 : // Entretien |
408 |
result := Sum (Slice (FBesLactE.BesAAEnt[j, a], PProfilT.DureeLact)) / d ; |
409 |
1 : // Lait |
410 |
result := Sum (Slice (FBesLactE.BesAALait[j, a], PProfilT.DureeLact)) / d ; |
411 |
else
|
412 |
result := 0 ;
|
413 |
end ;
|
414 |
end ;
|
415 |
|
416 |
// AffGraphAA
|
417 |
begin
|
418 |
ResetGraph ; |
419 |
Graph.Title.Text.Add (TabAA.Caption) ; |
420 |
Graph.SubTitle.Text.Add(StrDigestStd); |
421 |
Graph.LeftAxis.Title.Caption := Format ('%s (%s)', [CBAA3.Text, CBAA4.Text]) ;
|
422 |
Graph.BottomAxis.Title.Caption := _('Litter');
|
423 |
// Affichage des barres
|
424 |
for i := 0 to ListAA.Count - 1 do |
425 |
BarAA[i].Active := TRUE ; |
426 |
for i := 0 to ListAA.Count - 1 do |
427 |
BarAA[i].Clear ; |
428 |
if (CBAA4.ItemIndex = 1) |
429 |
then
|
430 |
for i := 0 to ListAA.Count - 1 do |
431 |
BarAA[i].MultiBar := mbStacked100 |
432 |
else
|
433 |
for i := 0 to ListAA.Count - 1 do |
434 |
BarAA[i].MultiBar := mbStacked ; |
435 |
h := CBAA3.ItemIndex + 1 ;
|
436 |
for j := 1 to NB_CYCLES do |
437 |
for i := 0 to ListAA.Count - 1 do |
438 |
BarAA[i].AddBar (AAY, Format ('%d', [j]), clTeeColor) ;
|
439 |
AjustEchelle (Graph) ; |
440 |
end ;
|
441 |
|
442 |
procedure TFResBesLactE.CBAA3Change (Sender : TObject) ;
|
443 |
begin
|
444 |
AffGraphAA ; |
445 |
end ;
|
446 |
|
447 |
procedure TFResBesLactE.CBAA4Change (Sender : TObject) ;
|
448 |
begin
|
449 |
AffGraphAA ; |
450 |
end ;
|
451 |
|
452 |
//////////////////
|
453 |
// Min?raux //
|
454 |
//////////////////
|
455 |
procedure TFResBesLactE.InitMin ;
|
456 |
begin
|
457 |
// BarMin : s?rie (barre) graphique
|
458 |
BarMin := TBarSeries.Create (Graph) ; |
459 |
BarMin.ParentChart := Graph ; |
460 |
BarMin.Title := ' ' ;
|
461 |
BarMin.SeriesColor := clTeal ; |
462 |
BarMin.BarPen.Color := BarMin.SeriesColor ; |
463 |
BarMin.Marks.Style := smsValue ; |
464 |
BarMin.Marks.ArrowLength := 0 ;
|
465 |
BarMin.Marks.Arrow.Visible := FALSE ; |
466 |
BarMin.Marks.Brush.Style := bsClear ; |
467 |
BarMin.Marks.Frame.Visible := FALSE ; |
468 |
BarMin.Marks.Font.Style := [fsBold] ; |
469 |
Graph.AddSeries (BarMin) ; |
470 |
end ;
|
471 |
|
472 |
procedure TFResBesLactE.AffGraphMin ;
|
473 |
var
|
474 |
j : integer ; |
475 |
|
476 |
// Ordonn?e
|
477 |
function MinY : double ;
|
478 |
var
|
479 |
d : double ; |
480 |
begin
|
481 |
// Diviseur
|
482 |
case CBMin4.ItemIndex of |
483 |
0 : // Dur?e |
484 |
d := PProfilT.DureeLact ; |
485 |
1 : // Aliment |
486 |
d := FBesLactE.AppAliTot[j] ; |
487 |
else
|
488 |
d := 1 ;
|
489 |
end ;
|
490 |
case CBMin3.ItemIndex of |
491 |
0 : // Phosphore digestible |
492 |
result := Sum (Slice (FBesLactE.BesP[j], PProfilT.DureeLact)) / d ; |
493 |
1 : // Calcium total |
494 |
result := Sum (Slice (FBesLactE.BesCa[j], PProfilT.DureeLact)) / d ; |
495 |
else
|
496 |
result := 0 ;
|
497 |
end ;
|
498 |
end ;
|
499 |
|
500 |
// AffGraphMin
|
501 |
begin
|
502 |
ResetGraph ; |
503 |
Graph.Legend.Visible := FALSE ; |
504 |
Graph.Title.Text.Add (TSMin.Caption) ; |
505 |
Graph.LeftAxis.Title.Caption := Format ('%s (%s)', [CBMin3.Text, CBMin4.Text]) ;
|
506 |
Graph.BottomAxis.Title.Caption := _('Litter');
|
507 |
// Affichage de la barre
|
508 |
BarMin.Active := TRUE ; |
509 |
BarMin.Clear ; |
510 |
for j := 1 to NB_CYCLES do |
511 |
BarMin.AddBar (MinY, Format ('%d', [j]), clTeeColor) ;
|
512 |
AjustEchelle (Graph) ; |
513 |
end ;
|
514 |
|
515 |
procedure TFResBesLactE.CBMin3Change(Sender: TObject);
|
516 |
begin
|
517 |
AffGraphMin ; |
518 |
end;
|
519 |
|
520 |
procedure TFResBesLactE.CBMin4Change(Sender: TObject);
|
521 |
begin
|
522 |
AffGraphMin ; |
523 |
end;
|
524 |
|
525 |
procedure TFResBesLactE.WMSysCommand(var Message: TWMSysCommand); |
526 |
begin
|
527 |
if Message.CmdType = SC_MINIMIZE
|
528 |
then
|
529 |
Application.Minimize |
530 |
else
|
531 |
inherited;
|
532 |
end;
|
533 |
|
534 |
end.
|