root / UFRationT.pas @ 5
Historique | Voir | Annoter | Télécharger (28,407 ko)
1 |
unit UFRationT ;
|
---|---|
2 |
|
3 |
interface
|
4 |
|
5 |
uses
|
6 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
7 |
Dialogs, StdCtrls, Buttons, ComCtrls, ExtCtrls, Math, PBNumEdit, PBSuperSpin, |
8 |
TeEngine, Series, TeeProcs, Chart, JvExControls, JvComponent, JvEnterTab, |
9 |
UVariables, gnugettext; |
10 |
|
11 |
type
|
12 |
TFRationT = class(TForm)
|
13 |
GBRation: TGroupBox; |
14 |
SBAddRation: TSpeedButton; |
15 |
SBDelRation: TSpeedButton; |
16 |
CBRation: TComboBox; |
17 |
GBRule: TGroupBox; |
18 |
LModeFin: TLabel; |
19 |
LNo: TLabel; |
20 |
SBAddRule: TSpeedButton; |
21 |
SBDelRule: TSpeedButton; |
22 |
LAli: TLabel; |
23 |
LBRule: TListBox; |
24 |
GBEnd: TGroupBox; |
25 |
LUnitFin: TLabel; |
26 |
PBValFin: TPBNumEdit; |
27 |
GBAjust: TGroupBox; |
28 |
LUnite: TLabel; |
29 |
CBUnite: TComboBox; |
30 |
PBa: TPBNumEdit; |
31 |
PBb: TPBNumEdit; |
32 |
La: TLabel; |
33 |
Graph: TChart; |
34 |
SeriesLigne: TLineSeries; |
35 |
SBRename: TSpeedButton; |
36 |
SBComment: TSpeedButton; |
37 |
CBModeFin: TComboBox; |
38 |
LType: TLabel; |
39 |
CBType: TComboBox; |
40 |
TC: TTabControl; |
41 |
LMoyenne: TLabel; |
42 |
PBMoyenne: TPBNumEdit; |
43 |
Pa: TPanel; |
44 |
Pc: TPanel; |
45 |
Lc: TLabel; |
46 |
PBc: TPBNumEdit; |
47 |
Pb: TPanel; |
48 |
Lb: TLabel; |
49 |
Pd: TPanel; |
50 |
Ld: TLabel; |
51 |
PQuantite: TPanel; |
52 |
LQuantite: TLabel; |
53 |
PBQuantite: TPBNumEdit; |
54 |
PBd: TPBSuperSpin; |
55 |
SBSave: TSpeedButton; |
56 |
SBPrint: TSpeedButton; |
57 |
GBParam: TGroupBox; |
58 |
PRation: TPanel; |
59 |
JvEnterAsTab: TJvEnterAsTab; |
60 |
procedure FormClose(Sender: TObject; var Action: TCloseAction); |
61 |
procedure FormShow(Sender: TObject);
|
62 |
procedure CBRationChange(Sender: TObject);
|
63 |
procedure SBAddRationClick(Sender: TObject);
|
64 |
procedure SBDelRationClick(Sender: TObject);
|
65 |
procedure LBRuleClick(Sender: TObject);
|
66 |
procedure LBRuleDrawItem(Control: TWinControl; Index: Integer;
|
67 |
Rect: TRect; State: TOwnerDrawState); |
68 |
procedure SBAddRuleClick(Sender: TObject);
|
69 |
procedure SBDelRuleClick(Sender: TObject);
|
70 |
procedure PBValFinChange(Sender: TObject);
|
71 |
procedure CBUniteChange(Sender: TObject);
|
72 |
procedure PBaChange(Sender: TObject);
|
73 |
procedure PBbChange(Sender: TObject);
|
74 |
procedure FormDeactivate(Sender: TObject);
|
75 |
procedure SBRenameClick(Sender: TObject);
|
76 |
procedure SBCommentClick(Sender: TObject);
|
77 |
procedure CBTypeChange(Sender: TObject);
|
78 |
procedure FormActivate(Sender: TObject);
|
79 |
procedure TCChange(Sender: TObject);
|
80 |
procedure PBcChange(Sender: TObject);
|
81 |
procedure PBdChange(Sender: TObject);
|
82 |
procedure PBQuantiteChange(Sender: TObject);
|
83 |
procedure SBSaveClick(Sender: TObject);
|
84 |
procedure SBPrintClick(Sender: TObject);
|
85 |
procedure FormCreate(Sender: TObject);
|
86 |
private
|
87 |
{ D?clarations priv?es }
|
88 |
Update, Modified : boolean ; |
89 |
IdxRationT, NbRule, NumRule : integer ; |
90 |
Rule : array[1..MAX_RULE] of RecRuleRationT ; |
91 |
procedure Save ;
|
92 |
procedure AffGraph ;
|
93 |
public
|
94 |
{ D?clarations publiques }
|
95 |
function StrModeFin (etat, regle : integer) : string ; |
96 |
function StrEquation (etat, regle : integer) : string ; |
97 |
end;
|
98 |
|
99 |
var
|
100 |
FRationT: TFRationT; |
101 |
|
102 |
implementation
|
103 |
|
104 |
uses
|
105 |
UStrings, UInit, UUtil, UFindRec, UEchelle, UCalcul, UFComment, UFRapRationT ; |
106 |
|
107 |
{$R *.dfm}
|
108 |
|
109 |
{ TFRationT }
|
110 |
|
111 |
procedure TFRationT.FormCreate(Sender: TObject);
|
112 |
begin
|
113 |
if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1 |
114 |
then
|
115 |
Font.Name := 'Arial Unicode MS';
|
116 |
TranslateComponent(Self); |
117 |
Constraints.MinWidth := 616 + (Width - ClientWidth);
|
118 |
Width := Constraints.MinWidth; |
119 |
Constraints.MinHeight := 476 + (Height - ClientHeight);
|
120 |
Height := Constraints.MinHeight; |
121 |
CBUnite.ItemIndex := 0;
|
122 |
CBModeFin.ItemIndex := 0;
|
123 |
CBType.ItemIndex := 0;
|
124 |
end;
|
125 |
|
126 |
procedure TFRationT.FormShow (Sender : TObject) ;
|
127 |
begin
|
128 |
Modified := FALSE ; |
129 |
StringsRationT (CBRation.Items, TRUE) ; |
130 |
SBAddRation.Enabled := IsComplete or (ListRationT.Count < 5) ; |
131 |
SBSave.Enabled := IsComplete or IsEducation ;
|
132 |
IdxRationT := -1 ;
|
133 |
// CBRationChange (nil) ;
|
134 |
end ;
|
135 |
|
136 |
procedure TFRationT.FormClose (Sender : TObject ; var Action : TCloseAction) ; |
137 |
begin
|
138 |
if Modified then Save ; |
139 |
Action := caFree ; |
140 |
NumWinRationT := -1 ;
|
141 |
end ;
|
142 |
|
143 |
procedure TFRationT.FormActivate (Sender : TObject) ;
|
144 |
begin
|
145 |
// if IdxRationT <> -1
|
146 |
// then
|
147 |
// PRationT := ListRationT[IdxRationT] ;
|
148 |
CBRationChange (nil) ;
|
149 |
GBParam.Enabled := IsComplete or IsEducation or IsEvaluation ; |
150 |
SBAddRule.Visible := GBParam.Enabled ; |
151 |
SBDelRule.Visible := GBParam.Enabled ; |
152 |
end ;
|
153 |
|
154 |
procedure TFRationT.FormDeactivate (Sender : TObject) ;
|
155 |
begin
|
156 |
if Modified then Save ; |
157 |
end ;
|
158 |
|
159 |
procedure TFRationT.Save ;
|
160 |
var
|
161 |
s : string ;
|
162 |
begin
|
163 |
Modified := FALSE ; |
164 |
if IsComplete or IsEducation |
165 |
then
|
166 |
if MessageDlg (Caption + sLineBreak + MsgSave, mtConfirmation, [mbYes, mbNo], 0) = mrYes |
167 |
then
|
168 |
begin
|
169 |
SaveRationT ; |
170 |
if not RationTValid (PRationT) |
171 |
then
|
172 |
MessageDlg(Format (MsgInvalidData, [Caption, PRationT.Nom]), mtWarning, [mbOK], 0) ;
|
173 |
end
|
174 |
else
|
175 |
begin
|
176 |
LoadRationT ; |
177 |
s := CBRation.Text ; |
178 |
StringsRationT (CBRation.Items, TRUE) ; |
179 |
if FindIdxRationT (s) = -1 |
180 |
then
|
181 |
begin
|
182 |
IdxRationT := -1 ;
|
183 |
CBRationChange (nil) ;
|
184 |
end
|
185 |
else
|
186 |
CBRation.ItemIndex := CBRation.Items.IndexOf (s) ; |
187 |
end ;
|
188 |
end ;
|
189 |
|
190 |
procedure TFRationT.CBRationChange (Sender : TObject) ;
|
191 |
begin
|
192 |
if (IdxRationT <> -1) and (CBRation.Text <> PRationT.Nom) |
193 |
then
|
194 |
if Modified then Save ; |
195 |
IdxRationT := FindIdxRationT (CBRation.Text) ; |
196 |
if IdxRationT = -1 |
197 |
then
|
198 |
begin
|
199 |
CBRation.Repaint ; |
200 |
SBDelRation.Enabled := FALSE ; |
201 |
SBRename.Enabled := FALSE ; |
202 |
SBComment.Enabled := FALSE ; |
203 |
SBSave.Enabled := FALSE ; |
204 |
SBPrint.Enabled := FALSE ; |
205 |
TC.Visible := FALSE ; |
206 |
end
|
207 |
else // Affichage de l'enregistrement |
208 |
begin
|
209 |
SBDelRation.Enabled := TRUE ; |
210 |
SBRename.Enabled := TRUE ; |
211 |
SBComment.Enabled := TRUE ; |
212 |
SBSave.Enabled := TRUE ; |
213 |
SBPrint.Enabled := TRUE ; |
214 |
TC.Visible := TRUE ; |
215 |
PRationT := ListRationT[IdxRationT] ; |
216 |
with PRationT^ do |
217 |
CBRation.Hint := Memo ; |
218 |
TCChange (nil) ;
|
219 |
end ;
|
220 |
end ;
|
221 |
|
222 |
procedure TFRationT.SBAddRationClick (Sender : TObject) ;
|
223 |
var
|
224 |
i, n, q : integer ; |
225 |
s : string ;
|
226 |
ok : boolean ; |
227 |
PBackup : PRecRationT ; |
228 |
begin
|
229 |
if Modified then Save ; |
230 |
if IdxRationT = -1 |
231 |
then
|
232 |
q := mrNo |
233 |
else
|
234 |
q := MessageDlg (MsgCopy, mtConfirmation, [mbYes, mbNo], 0) ;
|
235 |
// saisie du nouveau nom
|
236 |
s := '' ;
|
237 |
repeat
|
238 |
if InputQuery (FRationT.Caption, MsgName, s)
|
239 |
then // V?rification du nom |
240 |
begin
|
241 |
s := Trim (s) ; // Suppression des espaces au d?but et ? la fin
|
242 |
if s = '' |
243 |
then // Pas de nom |
244 |
begin
|
245 |
ok := FALSE ; |
246 |
MessageDlg (MsgNameEmpty, mtWarning, [mbOk], 0) ;
|
247 |
end
|
248 |
else
|
249 |
if Length (s) > 25 |
250 |
then // Nom trop long |
251 |
begin
|
252 |
ok := FALSE ; |
253 |
MessageDlg (Format (MsgNameTooLarge, [25]), mtWarning, [mbOk], 0) ; |
254 |
s := Copy (s, 1, 25) ; |
255 |
end
|
256 |
else
|
257 |
begin
|
258 |
ok := TRUE ; |
259 |
i := 0 ;
|
260 |
while ok and (i < ListRationT.Count) do |
261 |
begin
|
262 |
PRationT := ListRationT[i] ; |
263 |
if PRationT.Nom = s
|
264 |
then // Nom d?j? utilis? |
265 |
begin
|
266 |
ok := FALSE ; |
267 |
MessageDlg (MsgNameExists, mtWarning, [mbOk], 0) ;
|
268 |
end
|
269 |
else
|
270 |
Inc (i) ; |
271 |
end ;
|
272 |
end ;
|
273 |
end
|
274 |
else // Annulation |
275 |
begin
|
276 |
s := '' ;
|
277 |
if (IdxRationT <> -1) |
278 |
then
|
279 |
PRationT := ListRationT[IdxRationT] ; |
280 |
ok := TRUE ; |
281 |
end ;
|
282 |
until ok ;
|
283 |
if s <> '' |
284 |
then // Cr?ation du nouvel enregistrement |
285 |
begin
|
286 |
// recherche du premier num?ro libre
|
287 |
n := 0 ;
|
288 |
repeat
|
289 |
Inc (n) ; |
290 |
ok := TRUE ; |
291 |
i := 0 ;
|
292 |
while ok and (i < ListRationT.Count) do |
293 |
begin
|
294 |
PRationT := ListRationT[i] ; |
295 |
if PRationT.Num = n
|
296 |
then
|
297 |
ok := FALSE |
298 |
else
|
299 |
Inc (i) ; |
300 |
end ;
|
301 |
until ok ;
|
302 |
New (PRationT) ; |
303 |
with PRationT^ do |
304 |
begin
|
305 |
Nom := s ; |
306 |
Num := n ; |
307 |
if q = mrYes
|
308 |
then
|
309 |
begin
|
310 |
PBackup := ListRationT[IdxRationT] ; |
311 |
Memo := PBackup.Memo ; |
312 |
NbRuleGest := PBackup.NbRuleGest ; |
313 |
RuleGest := PBackup.RuleGest ; |
314 |
UniteGest := PBackup.UniteGest ; |
315 |
NbRuleLact := PBackup.NbRuleLact ; |
316 |
RuleLact := PBackup.RuleLact ; |
317 |
UniteLact := PBackup.UniteLact ; |
318 |
NbRuleISSF := PBackup.NbRuleISSF ; |
319 |
RuleISSF := PBackup.RuleISSF ; |
320 |
UniteISSF := PBackup.UniteISSF ; |
321 |
end
|
322 |
else
|
323 |
begin
|
324 |
Memo := '' ;
|
325 |
NbRuleGest := 1 ;
|
326 |
for i := 1 to MAX_RULE do |
327 |
with RuleGest[i] do |
328 |
begin
|
329 |
ModeFin := -1 ;
|
330 |
ValFin := 0 ;
|
331 |
Equation := 0 ;
|
332 |
a := 0 ;
|
333 |
b := 0 ;
|
334 |
c := 0 ;
|
335 |
d := 0 ;
|
336 |
end ;
|
337 |
UniteGest := 0 ;
|
338 |
NbRuleLact := 1 ;
|
339 |
for i := 1 to MAX_RULE do |
340 |
with RuleLact[i] do |
341 |
begin
|
342 |
ModeFin := -1 ;
|
343 |
ValFin := 0 ;
|
344 |
Equation := 0 ;
|
345 |
a := 0 ;
|
346 |
b := 0 ;
|
347 |
c := 0 ;
|
348 |
d := 28 ;
|
349 |
end ;
|
350 |
UniteLact := 0 ;
|
351 |
NbRuleISSF := 1 ;
|
352 |
for i := 1 to MAX_RULE do |
353 |
with RuleISSF[i] do |
354 |
begin
|
355 |
ModeFin := -1 ;
|
356 |
ValFin := 0 ;
|
357 |
Equation := 0 ;
|
358 |
a := 0 ;
|
359 |
b := 0 ;
|
360 |
c := 0 ;
|
361 |
d := 0 ;
|
362 |
end ;
|
363 |
UniteISSF := 0 ;
|
364 |
end ;
|
365 |
end ;
|
366 |
ListRationT.Add (PRationT) ; |
367 |
CBRation.Items.Add (PRationT.Nom) ; |
368 |
CBRation.ItemIndex := CBRation.Items.IndexOf (PRationT.Nom) ; |
369 |
CBRationChange (nil) ;
|
370 |
Modified := TRUE ; |
371 |
SBAddRation.Enabled := IsComplete or (ListRationT.Count < 5) ; |
372 |
SBCommentClick (nil) ;
|
373 |
end ;
|
374 |
end;
|
375 |
|
376 |
procedure TFRationT.SBDelRationClick (Sender : TObject) ;
|
377 |
var
|
378 |
i, j : integer ; |
379 |
begin
|
380 |
if RationTUsed (PRationT.Num)
|
381 |
then // Enregistrement utilis? |
382 |
MessageDlg (MsgDelErr, mtWarning, [mbOk], 0)
|
383 |
else // Suppression de l'enregistrement |
384 |
if MessageDlg (MsgDel, mtConfirmation, [mbYes, mbNo], 0) = mrYes |
385 |
then
|
386 |
begin
|
387 |
// Mise ? jour du 30/11/2006
|
388 |
// Suppression des r?f?rences masqu?es dans des simulations
|
389 |
if ListSimulT.Count > 0 |
390 |
then
|
391 |
for i := 0 to ListSimulT.Count - 1 do |
392 |
begin
|
393 |
PSimulT := ListSimulT[i] ; |
394 |
for j := 1 to NB_CYCLES do |
395 |
if PSimulT.Ration[j] = PRationT.Num
|
396 |
then
|
397 |
PSimulT.Ration[j] := -1 ;
|
398 |
end ;
|
399 |
SaveSimulT ; // Sauvegarde !
|
400 |
// Fin de mise ? jour
|
401 |
Dispose (PRationT) ; |
402 |
ListRationT.Delete (IdxRationT) ; |
403 |
SaveRationT ; // Sauvegarde !
|
404 |
Modified := FALSE ; |
405 |
CBRation.DeleteSelected ; |
406 |
IdxRationT := -1 ;
|
407 |
CBRation.ItemIndex := -1 ;
|
408 |
CBRationChange (nil) ;
|
409 |
SBAddRation.Enabled := IsComplete or (ListRationT.Count < 5) ; |
410 |
end ;
|
411 |
end ;
|
412 |
|
413 |
procedure TFRationT.SBRenameClick (Sender : TObject) ;
|
414 |
var
|
415 |
i : integer ; |
416 |
s : string ;
|
417 |
ok : boolean ; |
418 |
begin
|
419 |
// Saisie du nouveau nom
|
420 |
s := CBRation.Text ; |
421 |
repeat
|
422 |
if InputQuery (FRationT.Caption, MsgRename, s) and (s <> CBRation.Text) |
423 |
then // V?rification du nom |
424 |
begin
|
425 |
s := Trim (s) ; // Suppression des espaces au d?but et ? la fin
|
426 |
if s = '' |
427 |
then // Pas de nom |
428 |
begin
|
429 |
ok := FALSE ; |
430 |
MessageDlg (MsgNameEmpty, mtWarning, [mbOk], 0) ;
|
431 |
end
|
432 |
else
|
433 |
if Length (s) > 25 |
434 |
then // Nom trop long |
435 |
begin
|
436 |
ok := FALSE ; |
437 |
MessageDlg (Format (MsgNameTooLarge, [25]), mtWarning, [mbOk], 0) ; |
438 |
s := Copy (s, 1, 25) ; |
439 |
end
|
440 |
else
|
441 |
begin
|
442 |
ok := TRUE ; |
443 |
i := 0 ;
|
444 |
while ok and (i < ListRationT.Count) do |
445 |
begin
|
446 |
PRationT := ListRationT[i] ; |
447 |
if PRationT.Nom = s
|
448 |
then // Nom d?j? utilis? |
449 |
begin
|
450 |
ok := FALSE ; |
451 |
MessageDlg (MsgNameExists, mtWarning, [mbOk], 0) ;
|
452 |
end
|
453 |
else
|
454 |
Inc (i) ; |
455 |
end ;
|
456 |
end ;
|
457 |
end
|
458 |
else // Annulation |
459 |
begin
|
460 |
s := '' ;
|
461 |
ok := TRUE ; |
462 |
end ;
|
463 |
until ok ;
|
464 |
PRationT := ListRationT[IdxRationT] ; |
465 |
if s <> '' |
466 |
then // Renommer l'enregistrement |
467 |
begin
|
468 |
PRationT.Nom := s ; |
469 |
Modified := TRUE ; |
470 |
StringsRationT (CBRation.Items, TRUE) ; |
471 |
CBRation.ItemIndex := CBRation.Items.IndexOf (s) ; |
472 |
end ;
|
473 |
end ;
|
474 |
|
475 |
procedure TFRationT.SBCommentClick (Sender : TObject) ;
|
476 |
begin
|
477 |
// Saisie du commentaire
|
478 |
FComment := TFComment.Create (Self) ; |
479 |
with FComment do |
480 |
begin
|
481 |
Memo.Text := PRationT.Memo ; |
482 |
if ShowModal = mrOk
|
483 |
then // Commenter l'enregistrement |
484 |
begin
|
485 |
PRationT.Memo := Memo.Text ; |
486 |
Modified := TRUE ; |
487 |
CBRation.Hint := PRationT.Memo ; |
488 |
end ;
|
489 |
Release ; |
490 |
end ;
|
491 |
end ;
|
492 |
|
493 |
procedure TFRationT.SBSaveClick(Sender: TObject);
|
494 |
begin
|
495 |
SaveRationT ; |
496 |
if not RationTValid (PRationT) |
497 |
then
|
498 |
MessageDlg(Format (MsgInvalidData, [Caption, PRationT.Nom]), mtWarning, [mbOK], 0) ;
|
499 |
Modified := FALSE ; |
500 |
end;
|
501 |
|
502 |
procedure TFRationT.SBPrintClick(Sender: TObject);
|
503 |
begin
|
504 |
FRapRationT := TFRapRationT.Create (Self) ; |
505 |
FRapRationT.QRRapport.PreviewModal ; |
506 |
FRapRationT.Release ; |
507 |
end;
|
508 |
|
509 |
procedure TFRationT.TCChange (Sender : TObject) ;
|
510 |
var
|
511 |
i : integer ; |
512 |
begin
|
513 |
case TC.TabIndex of |
514 |
0 : // Gestation |
515 |
with PRationT^ do |
516 |
begin
|
517 |
NbRule := NbRuleGest ; |
518 |
for i := 1 to MAX_RULE do |
519 |
Rule[i] := RuleGest[i] ; |
520 |
CBUnite.ItemIndex := UniteGest ; |
521 |
end ;
|
522 |
1 : // Lactation |
523 |
with PRationT^ do |
524 |
begin
|
525 |
NbRule := NbRuleLact ; |
526 |
for i := 1 to MAX_RULE do |
527 |
Rule[i] := RuleLact[i] ; |
528 |
CBUnite.ItemIndex := UniteLact ; |
529 |
end ;
|
530 |
2 : // I.S.S.F. |
531 |
with PRationT^ do |
532 |
begin
|
533 |
NbRule := NbRuleISSF ; |
534 |
for i := 1 to MAX_RULE do |
535 |
Rule[i] := RuleISSF[i] ; |
536 |
CBUnite.ItemIndex := UniteISSF ; |
537 |
end ;
|
538 |
end ;
|
539 |
LBRule.Clear ; |
540 |
with PRationT^ do |
541 |
for i := 1 to NbRule do |
542 |
LBRule.Items.Add ('') ;
|
543 |
LBRule.ItemIndex := 0 ;
|
544 |
LBRuleClick (nil) ;
|
545 |
if TC.TabIndex = 1 |
546 |
then // Lactation |
547 |
CBType.Enabled := TRUE |
548 |
else
|
549 |
CBType.Enabled := FALSE ; |
550 |
AffGraph ; |
551 |
end ;
|
552 |
|
553 |
procedure TFRationT.LBRuleClick (Sender : TObject) ;
|
554 |
begin
|
555 |
NumRule := LBRule.ItemIndex + 1 ;
|
556 |
if LBRule.Items.Count < MAX_RULE
|
557 |
then
|
558 |
SBAddRule.Enabled := TRUE |
559 |
else
|
560 |
SBAddRule.Enabled := FALSE ; |
561 |
if NumRule = NbRule
|
562 |
then // Fin |
563 |
SBDelRule.Enabled := FALSE |
564 |
else
|
565 |
SBDelRule.Enabled := TRUE ; |
566 |
GBEnd.Visible := SBDelRule.Enabled ; |
567 |
with Rule[NumRule] do |
568 |
begin
|
569 |
Update := TRUE ; |
570 |
PBValFin.AsInteger := ValFin ; |
571 |
CBType.ItemIndex := Equation ; |
572 |
CBTypeChange (nil) ;
|
573 |
PBQuantite.AsFloat := a ; |
574 |
PBa.AsFloat := a ; |
575 |
PBb.AsFloat := b ; |
576 |
PBc.AsFloat := c ; |
577 |
PBd.AsInteger := d ; |
578 |
Update := FALSE ; |
579 |
end ;
|
580 |
end ;
|
581 |
|
582 |
procedure TFRationT.LBRuleDrawItem(Control: TWinControl; Index: Integer;
|
583 |
Rect: TRect; State: TOwnerDrawState); |
584 |
begin
|
585 |
with (Control as TListBox).Canvas do |
586 |
begin
|
587 |
// Cadre principal
|
588 |
FillRect(Rect); |
589 |
// Texte
|
590 |
SetTextAlign(Handle, TA_LEFT); |
591 |
Rect.Left := 22;
|
592 |
TextRect(Rect, Rect.Left, Rect.Top, StrModeFin(TC.TabIndex, Index + 1));
|
593 |
Rect.Left := 150;
|
594 |
TextRect(Rect, Rect.Left, Rect.Top, StrEquation(TC.TabIndex, Index + 1));
|
595 |
Rect.Left := 0;
|
596 |
// Num?ro
|
597 |
SetTextAlign(Handle, TA_RIGHT); |
598 |
Rect.Right := 14;
|
599 |
TextRect(Rect, Rect.Right, Rect.Top, Format('%d', [Index + 1])); |
600 |
end;
|
601 |
end;
|
602 |
|
603 |
procedure TFRationT.SBAddRuleClick (Sender : TObject) ;
|
604 |
var
|
605 |
i : integer ; |
606 |
begin
|
607 |
for i := NbRule downto NumRule do |
608 |
Rule[i + 1] := Rule[i] ;
|
609 |
with Rule[NumRule] do |
610 |
begin
|
611 |
ModeFin := 0 ;
|
612 |
ValFin := 0 ;
|
613 |
end ;
|
614 |
Inc (NbRule) ; |
615 |
case TC.TabIndex of |
616 |
0 : // Gestation |
617 |
with PRationT^ do |
618 |
begin
|
619 |
NbRuleGest := NbRule ; |
620 |
for i := 1 to MAX_RULE do |
621 |
RuleGest[i] := Rule[i] ; |
622 |
end ;
|
623 |
1 : // Lactation |
624 |
with PRationT^ do |
625 |
begin
|
626 |
NbRuleLact := NbRule ; |
627 |
for i := 1 to MAX_RULE do |
628 |
RuleLact[i] := Rule[i] ; |
629 |
end ;
|
630 |
2 : // I.S.S.F. |
631 |
with PRationT^ do |
632 |
begin
|
633 |
NbRuleISSF := NbRule ; |
634 |
for i := 1 to MAX_RULE do |
635 |
RuleISSF[i] := Rule[i] ; |
636 |
end ;
|
637 |
end ;
|
638 |
LBRule.Items.Add ('') ;
|
639 |
LBRule.ItemIndex := NumRule - 1 ;
|
640 |
LBRuleClick (nil) ;
|
641 |
Modified := TRUE ; |
642 |
ActiveControl := PBValFin ; |
643 |
end ;
|
644 |
|
645 |
procedure TFRationT.SBDelRuleClick (Sender : TObject) ;
|
646 |
var
|
647 |
i : integer ; |
648 |
begin
|
649 |
NbRule := NbRule - 1 ;
|
650 |
for i := NumRule to NbRule do |
651 |
Rule[i] := Rule[i + 1] ;
|
652 |
case TC.TabIndex of |
653 |
0 : // Gestation |
654 |
with PRationT^ do |
655 |
begin
|
656 |
NbRuleGest := NbRule ; |
657 |
for i := 1 to MAX_RULE do |
658 |
RuleGest[i] := Rule[i] ; |
659 |
end ;
|
660 |
1 : // Lactation |
661 |
with PRationT^ do |
662 |
begin
|
663 |
NbRuleLact := NbRule ; |
664 |
for i := 1 to MAX_RULE do |
665 |
RuleLact[i] := Rule[i] ; |
666 |
end ;
|
667 |
2 : // I.S.S.F. |
668 |
with PRationT^ do |
669 |
begin
|
670 |
NbRuleISSF := NbRule ; |
671 |
for i := 1 to MAX_RULE do |
672 |
RuleISSF[i] := Rule[i] ; |
673 |
end ;
|
674 |
end ;
|
675 |
i := NumRule ; // Position courante
|
676 |
LBRule.DeleteSelected ; |
677 |
LBRule.ItemIndex := i - 1 ;
|
678 |
LBRuleClick (nil) ;
|
679 |
ActiveControl := LBRule ; |
680 |
Modified := TRUE ; |
681 |
AffGraph ; |
682 |
end ;
|
683 |
|
684 |
procedure TFRationT.CBUniteChange (Sender : TObject) ;
|
685 |
begin
|
686 |
if not Update |
687 |
then
|
688 |
begin
|
689 |
Modified := TRUE ; |
690 |
case TC.TabIndex of |
691 |
0 : // Gestation |
692 |
with PRationT^ do |
693 |
UniteGest := CBUnite.ItemIndex ; |
694 |
1 : // Lactation |
695 |
with PRationT^ do |
696 |
UniteLact := CBUnite.ItemIndex ; |
697 |
2 : // I.S.S.F. |
698 |
with PRationT^ do |
699 |
UniteISSF := CBUnite.ItemIndex ; |
700 |
end ;
|
701 |
LBRule.Repaint ; |
702 |
AffGraph ; |
703 |
end ;
|
704 |
end ;
|
705 |
|
706 |
procedure TFRationT.PBValFinChange (Sender : TObject) ;
|
707 |
begin
|
708 |
if not Update |
709 |
then
|
710 |
begin
|
711 |
Modified := TRUE ; |
712 |
Rule[NumRule].ValFin := PBValFin.AsInteger ; |
713 |
case TC.TabIndex of |
714 |
0 : // Gestation |
715 |
with PRationT^ do |
716 |
begin
|
717 |
NbRuleGest := NbRule ; |
718 |
RuleGest[NumRule] := Rule[NumRule] ; |
719 |
end ;
|
720 |
1 : // Lactation |
721 |
with PRationT^ do |
722 |
begin
|
723 |
NbRuleLact := NbRule ; |
724 |
RuleLact[NumRule] := Rule[NumRule] ; |
725 |
end ;
|
726 |
2 : // I.S.S.F. |
727 |
with PRationT^ do |
728 |
begin
|
729 |
NbRuleISSF := NbRule ; |
730 |
RuleISSF[NumRule] := Rule[NumRule] ; |
731 |
end ;
|
732 |
end ;
|
733 |
LBRule.Repaint ; |
734 |
AffGraph ; |
735 |
end ;
|
736 |
end ;
|
737 |
|
738 |
procedure TFRationT.CBTypeChange (Sender : TObject) ;
|
739 |
begin
|
740 |
case CBType.ItemIndex of |
741 |
0 : // Constant |
742 |
begin
|
743 |
PQuantite.Visible := TRUE ; |
744 |
Pa.Visible := FALSE ; |
745 |
Pb.Visible := FALSE ; |
746 |
Pc.Visible := FALSE ; |
747 |
Pd.Visible := FALSE ; |
748 |
end ;
|
749 |
1 : // Lin?aire |
750 |
begin
|
751 |
PQuantite.Visible := FALSE ; |
752 |
Pa.Visible := TRUE ; |
753 |
Pb.Visible := TRUE ; |
754 |
Pc.Visible := FALSE ; |
755 |
Pd.Visible := FALSE ; |
756 |
end ;
|
757 |
2 : // Lin?aire-plateau |
758 |
begin
|
759 |
PQuantite.Visible := FALSE ; |
760 |
Pa.Visible := TRUE ; |
761 |
Pb.Visible := TRUE ; |
762 |
Pc.Visible := TRUE ; |
763 |
Pd.Visible := TRUE ; |
764 |
end ;
|
765 |
3 : // Curvilin?aire |
766 |
begin
|
767 |
PQuantite.Visible := FALSE ; |
768 |
Pa.Visible := TRUE ; |
769 |
Pb.Visible := FALSE ; |
770 |
Pc.Visible := TRUE ; |
771 |
Pd.Visible := TRUE ; |
772 |
end ;
|
773 |
end ;
|
774 |
if not Update |
775 |
then
|
776 |
begin
|
777 |
Modified := TRUE ; |
778 |
with Rule[NumRule] do |
779 |
Equation := CBType.ItemIndex ; |
780 |
case TC.TabIndex of |
781 |
0 : // Gestation |
782 |
with PRationT^ do |
783 |
begin
|
784 |
NbRuleGest := NbRule ; |
785 |
RuleGest[NumRule] := Rule[NumRule] ; |
786 |
end ;
|
787 |
1 : // Lactation |
788 |
with PRationT^ do |
789 |
begin
|
790 |
NbRuleLact := NbRule ; |
791 |
RuleLact[NumRule] := Rule[NumRule] ; |
792 |
end ;
|
793 |
2 : // I.S.S.F. |
794 |
with PRationT^ do |
795 |
begin
|
796 |
NbRuleISSF := NbRule ; |
797 |
RuleISSF[NumRule] := Rule[NumRule] ; |
798 |
end ;
|
799 |
end ;
|
800 |
LBRule.Repaint ; |
801 |
AffGraph ; |
802 |
end ;
|
803 |
end ;
|
804 |
|
805 |
procedure TFRationT.PBQuantiteChange (Sender : TObject) ;
|
806 |
begin
|
807 |
if not Update |
808 |
then
|
809 |
begin
|
810 |
Modified := TRUE ; |
811 |
Rule[NumRule].a := PBQuantite.AsFloat ; |
812 |
PBa.AsFloat := Rule[NumRule].a ; |
813 |
case TC.TabIndex of |
814 |
0 : // Gestation |
815 |
with PRationT^ do |
816 |
begin
|
817 |
NbRuleGest := NbRule ; |
818 |
RuleGest[NumRule] := Rule[NumRule] ; |
819 |
end ;
|
820 |
1 : // Lactation |
821 |
with PRationT^ do |
822 |
begin
|
823 |
NbRuleLact := NbRule ; |
824 |
RuleLact[NumRule] := Rule[NumRule] ; |
825 |
end ;
|
826 |
2 : // I.S.S.F. |
827 |
with PRationT^ do |
828 |
begin
|
829 |
NbRuleISSF := NbRule ; |
830 |
RuleISSF[NumRule] := Rule[NumRule] ; |
831 |
end ;
|
832 |
end ;
|
833 |
LBRule.Repaint ; |
834 |
AffGraph ; |
835 |
end ;
|
836 |
end ;
|
837 |
|
838 |
procedure TFRationT.PBaChange (Sender : TObject) ;
|
839 |
begin
|
840 |
if not Update |
841 |
then
|
842 |
begin
|
843 |
Modified := TRUE ; |
844 |
Rule[NumRule].a := PBa.AsFloat ; |
845 |
PBQuantite.AsFloat := Rule[NumRule].a ; |
846 |
case TC.TabIndex of |
847 |
0 : // Gestation |
848 |
with PRationT^ do |
849 |
begin
|
850 |
NbRuleGest := NbRule ; |
851 |
RuleGest[NumRule] := Rule[NumRule] ; |
852 |
end ;
|
853 |
1 : // Lactation |
854 |
with PRationT^ do |
855 |
begin
|
856 |
NbRuleLact := NbRule ; |
857 |
RuleLact[NumRule] := Rule[NumRule] ; |
858 |
end ;
|
859 |
2 : // I.S.S.F. |
860 |
with PRationT^ do |
861 |
begin
|
862 |
NbRuleISSF := NbRule ; |
863 |
RuleISSF[NumRule] := Rule[NumRule] ; |
864 |
end ;
|
865 |
end ;
|
866 |
LBRule.Repaint ; |
867 |
AffGraph ; |
868 |
end ;
|
869 |
end ;
|
870 |
|
871 |
procedure TFRationT.PBbChange (Sender : TObject) ;
|
872 |
begin
|
873 |
if not Update |
874 |
then
|
875 |
begin
|
876 |
Modified := TRUE ; |
877 |
Rule[NumRule].b := PBb.AsFloat ; |
878 |
case TC.TabIndex of |
879 |
0 : // Gestation |
880 |
with PRationT^ do |
881 |
begin
|
882 |
NbRuleGest := NbRule ; |
883 |
RuleGest[NumRule] := Rule[NumRule] ; |
884 |
end ;
|
885 |
1 : // Lactation |
886 |
with PRationT^ do |
887 |
begin
|
888 |
NbRuleLact := NbRule ; |
889 |
RuleLact[NumRule] := Rule[NumRule] ; |
890 |
end ;
|
891 |
2 : // I.S.S.F. |
892 |
with PRationT^ do |
893 |
begin
|
894 |
NbRuleISSF := NbRule ; |
895 |
RuleISSF[NumRule] := Rule[NumRule] ; |
896 |
end ;
|
897 |
end ;
|
898 |
LBRule.Repaint ; |
899 |
AffGraph ; |
900 |
end ;
|
901 |
end ;
|
902 |
|
903 |
procedure TFRationT.PBcChange (Sender : TObject) ;
|
904 |
begin
|
905 |
if not Update |
906 |
then
|
907 |
begin
|
908 |
Modified := TRUE ; |
909 |
Rule[NumRule].c := PBc.AsFloat ; |
910 |
case TC.TabIndex of |
911 |
0 : // Gestation |
912 |
with PRationT^ do |
913 |
begin
|
914 |
NbRuleGest := NbRule ; |
915 |
RuleGest[NumRule] := Rule[NumRule] ; |
916 |
end ;
|
917 |
1 : // Lactation |
918 |
with PRationT^ do |
919 |
begin
|
920 |
NbRuleLact := NbRule ; |
921 |
RuleLact[NumRule] := Rule[NumRule] ; |
922 |
end ;
|
923 |
2 : // I.S.S.F. |
924 |
with PRationT^ do |
925 |
begin
|
926 |
NbRuleISSF := NbRule ; |
927 |
RuleISSF[NumRule] := Rule[NumRule] ; |
928 |
end ;
|
929 |
end ;
|
930 |
LBRule.Repaint ; |
931 |
AffGraph ; |
932 |
end ;
|
933 |
end ;
|
934 |
|
935 |
procedure TFRationT.PBdChange (Sender : TObject) ;
|
936 |
begin
|
937 |
if not Update |
938 |
then
|
939 |
begin
|
940 |
Modified := TRUE ; |
941 |
Rule[NumRule].d := PBd.AsInteger ; |
942 |
case TC.TabIndex of |
943 |
0 : // Gestation |
944 |
with PRationT^ do |
945 |
begin
|
946 |
NbRuleGest := NbRule ; |
947 |
RuleGest[NumRule] := Rule[NumRule] ; |
948 |
end ;
|
949 |
1 : // Lactation |
950 |
with PRationT^ do |
951 |
begin
|
952 |
NbRuleLact := NbRule ; |
953 |
RuleLact[NumRule] := Rule[NumRule] ; |
954 |
end ;
|
955 |
2 : // I.S.S.F. |
956 |
with PRationT^ do |
957 |
begin
|
958 |
NbRuleISSF := NbRule ; |
959 |
RuleISSF[NumRule] := Rule[NumRule] ; |
960 |
end ;
|
961 |
end ;
|
962 |
LBRule.Repaint ; |
963 |
AffGraph ; |
964 |
end ;
|
965 |
end ;
|
966 |
|
967 |
function TFRationT.StrModeFin (etat, regle : integer) : string ; |
968 |
var
|
969 |
Nb : integer ; |
970 |
Rec : RecRuleRationT ; |
971 |
begin
|
972 |
case etat of |
973 |
0 : // Gestation |
974 |
Nb := PRationT.NbRuleGest ; |
975 |
1 : // Lactation |
976 |
Nb := PRationT.NbRuleLact ; |
977 |
else // I.S.S.F. |
978 |
Nb := PRationT.NbRuleISSF ; |
979 |
end ;
|
980 |
if regle = Nb
|
981 |
then // Fin |
982 |
case etat of |
983 |
0 : // Gestation |
984 |
result := StrMiseBas ; |
985 |
1 : // Lactation |
986 |
result := StrSevrage ; |
987 |
2 : // I.S.S.F. |
988 |
result := StrSaillie ; |
989 |
end
|
990 |
else
|
991 |
begin
|
992 |
case etat of |
993 |
0 : // Gestation |
994 |
Rec := PRationT.RuleGest[regle] ; |
995 |
1 : // Lactation |
996 |
Rec := PRationT.RuleLact[regle] ; |
997 |
2 : // I.S.S.F. |
998 |
Rec := PRationT.RuleISSF[regle] ; |
999 |
end ;
|
1000 |
with Rec do |
1001 |
case ModeFin of |
1002 |
0 : // Dur?e |
1003 |
result := Format ('%s = %d %s', [CBModeFin.Items[ModeFin], ValFin, StrJ]) ;
|
1004 |
else
|
1005 |
result := '' ;
|
1006 |
end ;
|
1007 |
end ;
|
1008 |
end ;
|
1009 |
|
1010 |
function TFRationT.StrEquation (etat, regle : integer) : string ; |
1011 |
var
|
1012 |
Rec : RecRuleRationT ; |
1013 |
begin
|
1014 |
case etat of |
1015 |
0 : // Gestation |
1016 |
Rec := PRationT.RuleGest[regle] ; |
1017 |
1 : // Lactation |
1018 |
Rec := PRationT.RuleLact[regle] ; |
1019 |
2 : // I.S.S.F. |
1020 |
Rec := PRationT.RuleISSF[regle] ; |
1021 |
end ;
|
1022 |
with Rec do |
1023 |
case Equation of |
1024 |
0 : // Constant (a) |
1025 |
result := Format ('%s=%s', [CBUnite.Text, DblToStr (a, PBa.Decimals)]) ;
|
1026 |
1 : // Lin?aire (a+b*jour) |
1027 |
result := Format ('%s=%s+%s*%s', [CBUnite.Text, DblToStr (a, PBa.Decimals), DblToStr (b, PBb.Decimals), _('Day')]) ; |
1028 |
else
|
1029 |
result := Format ('%s=%s', [CBUnite.Text, CBType.Items[Equation]]) ;
|
1030 |
end ;
|
1031 |
end ;
|
1032 |
|
1033 |
procedure TFRationT.AffGraph ;
|
1034 |
var
|
1035 |
f, i, j, k : integer ; |
1036 |
q, t : double ; |
1037 |
ok : boolean ; |
1038 |
|
1039 |
function Quantite : double ;
|
1040 |
begin
|
1041 |
with Rule[k] do |
1042 |
case Equation of |
1043 |
0 : // Constant |
1044 |
result := a ; |
1045 |
1 : // Lin?aire |
1046 |
result := a + b * (i - 1) ;
|
1047 |
2 : // Lin?aire-plateau |
1048 |
result := LPvaleur (a, b, c, i, d) ; |
1049 |
3 : // Curvilin?aire |
1050 |
result := CLvaleur (a, c, i, d) ; |
1051 |
else
|
1052 |
result := 0 ;
|
1053 |
end ;
|
1054 |
end ;
|
1055 |
|
1056 |
begin
|
1057 |
Graph.LeftAxis.Title.Caption := CBUnite.Text ; |
1058 |
SeriesLigne.Clear ; |
1059 |
ok := TRUE ; |
1060 |
case TC.TabIndex of |
1061 |
0 : // Gestation |
1062 |
begin
|
1063 |
f := 114 ;
|
1064 |
Graph.BottomAxis.Increment := 20 ;
|
1065 |
Graph.BottomAxis.MinorTickCount := 3 ;
|
1066 |
for k := 1 to NbRule do |
1067 |
if Rule[k].a = 0 then ok := FALSE ; |
1068 |
end ;
|
1069 |
1 : // Lactation |
1070 |
begin
|
1071 |
f := 28 ;
|
1072 |
Graph.BottomAxis.Increment := 7 ;
|
1073 |
Graph.BottomAxis.MinorTickCount := 6 ;
|
1074 |
for k := 1 to NbRule do |
1075 |
case Rule[k].Equation of |
1076 |
1 : // Lin?aire |
1077 |
begin
|
1078 |
if Rule[k].a = 0 then ok := FALSE ; |
1079 |
if Rule[k].b = 0 then ok := FALSE ; |
1080 |
end ;
|
1081 |
2 : // Lin?aire-plateau |
1082 |
begin
|
1083 |
if Rule[k].a = 0 then ok := FALSE ; |
1084 |
if Rule[k].b = 0 then ok := FALSE ; |
1085 |
if Rule[k].c <= Rule[k].a then ok := FALSE ; |
1086 |
end ;
|
1087 |
3 : // Curvilin?aire |
1088 |
begin
|
1089 |
if Rule[k].a = 0 then ok := FALSE ; |
1090 |
if Rule[k].c <= Rule[k].a then ok := FALSE ; |
1091 |
end ;
|
1092 |
else // Constant |
1093 |
if Rule[k].a = 0 then ok := FALSE ; |
1094 |
end ;
|
1095 |
end ;
|
1096 |
else // I.S.S.F. |
1097 |
begin
|
1098 |
f := 10 ;
|
1099 |
Graph.BottomAxis.Increment := 1 ;
|
1100 |
Graph.BottomAxis.MinorTickCount := 0 ;
|
1101 |
for k := 1 to NbRule do |
1102 |
if Rule[k].a = 0 then ok := FALSE ; |
1103 |
end ;
|
1104 |
end ;
|
1105 |
if not ok then Exit ; |
1106 |
t := 0 ;
|
1107 |
j := 0 ;
|
1108 |
for k := 1 to NbRule do |
1109 |
with Rule[k] do |
1110 |
begin
|
1111 |
if (ModeFin = 0) and (ValFin > 0) |
1112 |
then // R?gle dur?e |
1113 |
begin
|
1114 |
for i := j + 1 to j + ValFin do |
1115 |
begin
|
1116 |
q := Quantite ; |
1117 |
SeriesLigne.AddXY (i, q) ; |
1118 |
t := t + q ; |
1119 |
end ;
|
1120 |
j := j + ValFin ; |
1121 |
end
|
1122 |
else
|
1123 |
if (k = NbRule) and (j < f) |
1124 |
then // R?gle fin |
1125 |
begin
|
1126 |
for i := j + 1 to f do |
1127 |
begin
|
1128 |
q := Quantite ; |
1129 |
SeriesLigne.AddXY (i, q) ; |
1130 |
t := t + q ; |
1131 |
end ;
|
1132 |
j := f ; |
1133 |
end ;
|
1134 |
end ;
|
1135 |
PBMoyenne.AsFloat := t / j ; |
1136 |
AjustEchelle (Graph) ; |
1137 |
end ;
|
1138 |
|
1139 |
end.
|