root / UnitIngredientCreation.pas @ 13
Historique | Voir | Annoter | Télécharger (27,823 ko)
1 |
unit UnitIngredientCreation;
|
---|---|
2 |
|
3 |
interface
|
4 |
|
5 |
uses
|
6 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
7 |
Dialogs, gnugettext, StdCtrls, Mask, DB, DBCtrls, JvExMask, JvSpin, |
8 |
JvExStdCtrls, JvEdit, JvValidateEdit, ComCtrls, JvExControls, JvEnterTab, |
9 |
JvButton, JvCtrls, ActnList, ImgList, ExtCtrls; |
10 |
|
11 |
type
|
12 |
TFormIngredientCreation = class(TForm)
|
13 |
ValidateEditMSCopy: TJvValidateEdit; |
14 |
ValidateEditModel: TJvValidateEdit; |
15 |
PageControlCreation: TPageControl; |
16 |
TabSheetCopy: TTabSheet; |
17 |
TabSheetOriginal: TTabSheet; |
18 |
ValidateEditMSOriginal: TJvValidateEdit; |
19 |
GroupBoxOriginalStep2: TGroupBox; |
20 |
GroupBoxOriginalStep5: TGroupBox; |
21 |
GroupBoxOriginalStep4: TGroupBox; |
22 |
GroupBoxOriginalStep6: TGroupBox; |
23 |
ValidateEditMAT: TJvValidateEdit; |
24 |
ValidateEditMM: TJvValidateEdit; |
25 |
CheckBoxMAT: TCheckBox; |
26 |
CheckBoxMM: TCheckBox; |
27 |
GroupBoxOriginalStep7: TGroupBox; |
28 |
GroupBoxOriginalStep3: TGroupBox; |
29 |
ValidateEditMG: TJvValidateEdit; |
30 |
CheckBoxMG: TCheckBox; |
31 |
CheckBoxEB: TCheckBox; |
32 |
ValidateEditEB: TJvValidateEdit; |
33 |
ValidateEditAmidon: TJvValidateEdit; |
34 |
CheckBoxAmidon: TCheckBox; |
35 |
ValidateEditSucres: TJvValidateEdit; |
36 |
CheckBoxSucres: TCheckBox; |
37 |
ValidateEditCB: TJvValidateEdit; |
38 |
ValidateEditNDF: TJvValidateEdit; |
39 |
ValidateEditADF: TJvValidateEdit; |
40 |
CheckBoxCB: TCheckBox; |
41 |
CheckBoxNDF: TCheckBox; |
42 |
CheckBoxADF: TCheckBox; |
43 |
GroupBoxCopyStep1: TGroupBox; |
44 |
GroupBoxCopyStep2: TGroupBox; |
45 |
GroupBoxOriginalStep1: TGroupBox; |
46 |
EnterAsTab: TJvEnterAsTab; |
47 |
ButtonNext: TButton; |
48 |
LabelName: TLabel; |
49 |
LabelClass: TLabel; |
50 |
LabelDefinition: TLabel; |
51 |
LabelModel: TLabel; |
52 |
LabelMSCopy: TLabel; |
53 |
LabelMSCopyWarning: TLabel; |
54 |
LabelOptionComment: TLabel; |
55 |
LabelMM: TLabel; |
56 |
LabelMG: TLabel; |
57 |
LabelEB: TLabel; |
58 |
LabelMGComment: TLabel; |
59 |
LabelEBComment: TLabel; |
60 |
LabelCB: TLabel; |
61 |
LabelNDF: TLabel; |
62 |
LabelADF: TLabel; |
63 |
LabelAmidon: TLabel; |
64 |
LabelSucres: TLabel; |
65 |
LabelMAT: TLabel; |
66 |
LabelMSOriginal: TLabel; |
67 |
LabelMSOriginalWarning: TLabel; |
68 |
ComboBoxClass: TComboBox; |
69 |
ComboBoxModel: TComboBox; |
70 |
ComboBoxMSCopy: TComboBox; |
71 |
ComboBoxMM: TComboBox; |
72 |
ComboBoxMG: TComboBox; |
73 |
ComboBoxEB: TComboBox; |
74 |
ComboBoxFibre: TComboBox; |
75 |
ComboBoxAmidon: TComboBox; |
76 |
ComboBoxSucres: TComboBox; |
77 |
ComboBoxMAT: TComboBox; |
78 |
ComboBoxMSOriginal: TComboBox; |
79 |
EditName: TEdit; |
80 |
MemoDefinition: TMemo; |
81 |
ImageListIcons: TImageList; |
82 |
ActionListButtons: TActionList; |
83 |
ActionHelp: TAction; |
84 |
JvImgBtnHelp: TJvImgBtn; |
85 |
JvImgBtnOK: TJvImgBtn; |
86 |
JvImgBtnCancel: TJvImgBtn; |
87 |
ActionOK: TAction; |
88 |
ActionCancel: TAction; |
89 |
PanelButtons: TPanel; |
90 |
PanelHead: TPanel; |
91 |
procedure FormCreate(Sender: TObject);
|
92 |
procedure ComboBoxClassChange(Sender: TObject);
|
93 |
procedure ComboBoxModelChange(Sender: TObject);
|
94 |
procedure ComboBoxMSCopyChange(Sender: TObject);
|
95 |
procedure ButtonNextClick(Sender: TObject);
|
96 |
procedure ComboBoxMSOriginalChange(Sender: TObject);
|
97 |
procedure ComboBoxMMChange(Sender: TObject);
|
98 |
procedure ComboBoxMATChange(Sender: TObject);
|
99 |
procedure ComboBoxMGChange(Sender: TObject);
|
100 |
procedure ComboBoxEBChange(Sender: TObject);
|
101 |
procedure ComboBoxFibreChange(Sender: TObject);
|
102 |
procedure ComboBoxAmidonChange(Sender: TObject);
|
103 |
procedure ComboBoxSucresChange(Sender: TObject);
|
104 |
procedure CheckBoxMMClick(Sender: TObject);
|
105 |
procedure CheckBoxMATClick(Sender: TObject);
|
106 |
procedure CheckBoxMGClick(Sender: TObject);
|
107 |
procedure CheckBoxEBClick(Sender: TObject);
|
108 |
procedure CheckBoxCBClick(Sender: TObject);
|
109 |
procedure CheckBoxNDFClick(Sender: TObject);
|
110 |
procedure CheckBoxADFClick(Sender: TObject);
|
111 |
procedure CheckBoxAmidonClick(Sender: TObject);
|
112 |
procedure CheckBoxSucresClick(Sender: TObject);
|
113 |
procedure FormDestroy(Sender: TObject);
|
114 |
procedure ActionHelpExecute(Sender: TObject);
|
115 |
procedure ActionOKExecute(Sender: TObject);
|
116 |
procedure ActionCancelExecute(Sender: TObject);
|
117 |
procedure NumEditKeyDown(Sender: TObject; var Key: Word; |
118 |
Shift: TShiftState); |
119 |
procedure NumEditKeyPress(Sender: TObject; var Key: Char); |
120 |
private
|
121 |
{ D?clarations priv?es }
|
122 |
ModelList: TStrings; |
123 |
procedure EditActivate(Edit: TJvValidateEdit);
|
124 |
procedure EditEmpty(Edit: TJvValidateEdit);
|
125 |
public
|
126 |
{ D?clarations publiques }
|
127 |
end;
|
128 |
|
129 |
var
|
130 |
FormIngredientCreation: TFormIngredientCreation; |
131 |
|
132 |
implementation
|
133 |
|
134 |
{$R *.dfm}
|
135 |
|
136 |
uses
|
137 |
UnitDeclaration, UnitOptions; |
138 |
|
139 |
var
|
140 |
VK_Separator: boolean; |
141 |
|
142 |
procedure TFormIngredientCreation.ActionCancelExecute(Sender: TObject);
|
143 |
begin
|
144 |
ModalResult := mrCancel; |
145 |
end;
|
146 |
|
147 |
procedure TFormIngredientCreation.ActionHelpExecute(Sender: TObject);
|
148 |
begin
|
149 |
Application.HelpContext(HelpContext); |
150 |
end;
|
151 |
|
152 |
procedure TFormIngredientCreation.ActionOKExecute(Sender: TObject);
|
153 |
var
|
154 |
NewId: Integer; |
155 |
NewName, NewComment: String;
|
156 |
Nb: Integer; |
157 |
MM, MAT, MG, Fibre, Amidon, Sucres, CB, NDF, ADF: Double; |
158 |
USFormatSettings: TFormatSettings; |
159 |
begin
|
160 |
NewName := Trim(EditName.Text); |
161 |
NewComment := MemoDefinition.Text; |
162 |
if NewName = '' |
163 |
then
|
164 |
begin
|
165 |
MessageDlg(_('You must specify a name for this ingredient.'), mtError, [mbOK], 0); |
166 |
ActiveControl := EditName; |
167 |
Exit; |
168 |
end;
|
169 |
if DataModuleDeclaration.UserList.IndexOf(NewName) <> -1 |
170 |
then
|
171 |
begin
|
172 |
MessageDlg(_('This name is already used, please specify another name.'), mtError, [mbOK], 0); |
173 |
ActiveControl := EditName; |
174 |
Exit; |
175 |
end;
|
176 |
if ComboBoxClass.ItemIndex = -1 |
177 |
then
|
178 |
begin
|
179 |
MessageDlg(_('You must specify a class for this ingredient.'), mtError, [mbOK], 0); |
180 |
ActiveControl := ComboBoxClass; |
181 |
Exit; |
182 |
end;
|
183 |
if PageControlCreation.TabIndex = 0 |
184 |
then // Copie |
185 |
begin
|
186 |
if ComboBoxModel.ItemIndex = -1 |
187 |
then
|
188 |
begin
|
189 |
MessageDlg(_('You must specify a reference for this ingredient.'), mtError, [mbOK], 0); |
190 |
ActiveControl := ComboBoxModel; |
191 |
Exit; |
192 |
end;
|
193 |
if ValidateEditMSCopy.Value = 0 |
194 |
then
|
195 |
begin
|
196 |
MessageDlg(_('You must specify a dry matter value for this ingredient.'), mtError, [mbOK], 0); |
197 |
ActiveControl := ValidateEditMSCopy; |
198 |
Exit; |
199 |
end;
|
200 |
end
|
201 |
else // Cr?ation originale |
202 |
begin
|
203 |
if not CheckBoxMM.Checked |
204 |
then
|
205 |
begin
|
206 |
MessageDlg(_('You must specify an ash value for this ingredient.'), mtError, [mbOK], 0); |
207 |
ActiveControl := CheckBoxMM; |
208 |
Exit; |
209 |
end;
|
210 |
if not CheckBoxMAT.Checked |
211 |
then
|
212 |
begin
|
213 |
MessageDlg(_('You must specify a crude protein value for this ingredient.'), mtError, [mbOK], 0); |
214 |
ActiveControl := CheckBoxMAT; |
215 |
Exit; |
216 |
end;
|
217 |
if not CheckBoxCB.Checked and not CheckBoxNDF.Checked and not CheckBoxADF.Checked |
218 |
then
|
219 |
begin
|
220 |
MessageDlg(_('You must specify a fiber value (crude fiber, NDF or ADF) for this ingredient.'), mtError, [mbOK], 0); |
221 |
ActiveControl := CheckBoxCB; |
222 |
Exit; |
223 |
end;
|
224 |
if not CheckBoxMG.Checked and not CheckBoxEB.Checked |
225 |
then
|
226 |
begin
|
227 |
MessageDlg(_('You must specify a crude fat value or a gross energy value for this ingredient.'), mtError, [mbOK], 0); |
228 |
ActiveControl := CheckBoxMG; |
229 |
Exit; |
230 |
end;
|
231 |
with DataModuleDeclaration do |
232 |
RapMS := InputProximal(ValidateEditMSOriginal.AsFloat, 1, 1, ComboBoxMSOriginal.ItemIndex); |
233 |
if CheckBoxMM.Checked
|
234 |
then
|
235 |
with DataModuleDeclaration do |
236 |
MM := InputProximal(ValidateEditMM.AsFloat, RapMS, ComboBoxMM.ItemIndex div 2, ComboBoxMM.ItemIndex mod 2) |
237 |
else
|
238 |
MM := 0;
|
239 |
if CheckBoxMAT.Checked
|
240 |
then
|
241 |
with DataModuleDeclaration do |
242 |
MAT := InputProximal(ValidateEditMAT.AsFloat, RapMS, ComboBoxMAT.ItemIndex div 2, ComboBoxMAT.ItemIndex mod 2) |
243 |
else
|
244 |
MAT := 0;
|
245 |
if CheckBoxMG.Checked
|
246 |
then
|
247 |
with DataModuleDeclaration do |
248 |
MG := InputProximal(ValidateEditMG.AsFloat, RapMS, ComboBoxMG.ItemIndex div 2, ComboBoxMG.ItemIndex mod 2) |
249 |
else
|
250 |
MG := 0;
|
251 |
Nb := 0;
|
252 |
if CheckBoxCB.Checked
|
253 |
then
|
254 |
begin
|
255 |
with DataModuleDeclaration do |
256 |
CB := InputProximal(ValidateEditCB.AsFloat, RapMS, ComboBoxFibre.ItemIndex div 2, ComboBoxFibre.ItemIndex mod 2); |
257 |
Inc(Nb); |
258 |
end
|
259 |
else
|
260 |
CB := 0;
|
261 |
if CheckBoxNDF.Checked
|
262 |
then
|
263 |
begin
|
264 |
with DataModuleDeclaration do |
265 |
NDF := InputProximal(ValidateEditNDF.AsFloat, RapMS, ComboBoxFibre.ItemIndex div 2, ComboBoxFibre.ItemIndex mod 2); |
266 |
Inc(Nb); |
267 |
end
|
268 |
else
|
269 |
NDF := 0;
|
270 |
if CheckBoxADF.Checked
|
271 |
then
|
272 |
begin
|
273 |
with DataModuleDeclaration do |
274 |
ADF := InputProximal(ValidateEditADF.AsFloat, RapMS, ComboBoxFibre.ItemIndex div 2, ComboBoxFibre.ItemIndex mod 2); |
275 |
Inc(Nb); |
276 |
end
|
277 |
else
|
278 |
ADF := 0;
|
279 |
if Nb = 0 |
280 |
then
|
281 |
Fibre := 0
|
282 |
else // Moyenne des ?quations significatives |
283 |
Fibre := (CB * NDF_CB + NDF + ADF * NDF_ADF) / Nb; |
284 |
if CheckBoxAmidon.Checked
|
285 |
then
|
286 |
with DataModuleDeclaration do |
287 |
Amidon := InputProximal(ValidateEditAmidon.AsFloat, RapMS, ComboBoxAmidon.ItemIndex div 2, ComboBoxAmidon.ItemIndex mod 2) |
288 |
else
|
289 |
Amidon := 0;
|
290 |
if CheckBoxSucres.Checked
|
291 |
then
|
292 |
with DataModuleDeclaration do |
293 |
Sucres := InputProximal(ValidateEditSucres.AsFloat, RapMS, ComboBoxSucres.ItemIndex div 2, ComboBoxSucres.ItemIndex mod 2) |
294 |
else
|
295 |
Sucres := 0;
|
296 |
if MM + MAT + MG + Fibre + Amidon + Sucres > MAX_SUM
|
297 |
then
|
298 |
if MessageDlg(_('The sum of nutrients is estimated to more than 100% of the dry matter.' + sLineBreak + 'Are you sure you want to continue?'), mtError, [mbYes, mbNo], 0) <> mrYes |
299 |
then
|
300 |
Exit; |
301 |
end;
|
302 |
with DataModuleDeclaration do |
303 |
begin
|
304 |
// Rechercher une valeur pour le champs Id
|
305 |
TableIngredients := DBUser.GetTable('SELECT Id FROM Ingredients ORDER BY Id');
|
306 |
with TableIngredients do |
307 |
try
|
308 |
if RowCount > 0 |
309 |
then
|
310 |
begin
|
311 |
MoveLast; |
312 |
NewId := FieldAsInteger(FieldIndex['Id']) + 1; |
313 |
end
|
314 |
else
|
315 |
NewId := 1;
|
316 |
finally
|
317 |
Free; |
318 |
end;
|
319 |
// Cr?er la nouvelle mati?re premi?re
|
320 |
GetLocaleFormatSettings(1033, USFormatSettings);
|
321 |
DBUser.BeginTransaction; |
322 |
try
|
323 |
if PageControlCreation.TabIndex = 0 |
324 |
then // Copie |
325 |
DBUser.ExecSQL('INSERT INTO Ingredients (Id, Name, Definition, Class, Model, MS, Bonus) VALUES ('
|
326 |
+ Format('%d, ', [NewId])
|
327 |
+ Format('%s, ', [QuotedStr(NewName)])
|
328 |
+ Format('%s, ', [QuotedStr(NewComment)])
|
329 |
+ Format('%d, ', [ComboBoxClass.ItemIndex + 1]) |
330 |
+ Format('%d, ', [ValidateEditModel.AsInteger])
|
331 |
+ Format('%.15f, ', [InputProximal(ValidateEditMSCopy.AsFloat, 1, 1, ComboBoxMSCopy.ItemIndex)], USFormatSettings) |
332 |
+ '0)')
|
333 |
else // Cr?ation originale |
334 |
begin
|
335 |
DBUser.ExecSQL('INSERT INTO Ingredients (Id, Name, Definition, Class, MS, Bonus) VALUES ('
|
336 |
+ Format('%d, ', [NewId])
|
337 |
+ Format('%s, ', [QuotedStr(NewName)])
|
338 |
+ Format('%s, ', [QuotedStr(NewComment)])
|
339 |
+ Format('%d, ', [ComboBoxClass.ItemIndex + 1]) |
340 |
+ Format('%.15f, ', [RapMS], USFormatSettings)
|
341 |
+ '0)');
|
342 |
if CheckBoxMM.Checked
|
343 |
then
|
344 |
DBUser.ExecSQL('UPDATE Ingredients '
|
345 |
+ Format('SET MM = %.15f ', [InputProximal(ValidateEditMM.AsFloat, RapMS, ComboBoxMM.ItemIndex div 2, ComboBoxMM.ItemIndex mod 2)], USFormatSettings) |
346 |
+ Format('WHERE Id = %d', [NewId]));
|
347 |
if CheckBoxMAT.Checked
|
348 |
then
|
349 |
DBUser.ExecSQL('UPDATE Ingredients '
|
350 |
+ Format('SET MAT = %.15f ', [InputProximal(ValidateEditMAT.AsFloat, RapMS, ComboBoxMAT.ItemIndex div 2, ComboBoxMAT.ItemIndex mod 2)], USFormatSettings) |
351 |
+ Format('WHERE Id = %d', [NewId]));
|
352 |
if CheckBoxMG.Checked
|
353 |
then
|
354 |
DBUser.ExecSQL('UPDATE Ingredients '
|
355 |
+ Format('SET MG = %.15f ', [InputProximal(ValidateEditMG.AsFloat, RapMS, ComboBoxMG.ItemIndex div 2, ComboBoxMG.ItemIndex mod 2)], USFormatSettings) |
356 |
+ Format('WHERE Id = %d', [NewId]));
|
357 |
if CheckBoxEB.Checked
|
358 |
then
|
359 |
DBUser.ExecSQL('UPDATE Ingredients '
|
360 |
+ Format('SET EB = %.15f ', [InputEnergy(ValidateEditEB.AsFloat, RapMS, ComboBoxEB.ItemIndex div 2, ComboBoxEB.ItemIndex mod 2)], USFormatSettings) |
361 |
+ Format('WHERE Id = %d', [NewId]));
|
362 |
if CheckBoxCB.Checked
|
363 |
then
|
364 |
DBUser.ExecSQL('UPDATE Ingredients '
|
365 |
+ Format('SET CB = %.15f ', [InputProximal(ValidateEditCB.AsFloat, RapMS, ComboBoxFibre.ItemIndex div 2, ComboBoxFibre.ItemIndex mod 2)], USFormatSettings) |
366 |
+ Format('WHERE Id = %d', [NewId]));
|
367 |
if CheckBoxNDF.Checked
|
368 |
then
|
369 |
DBUser.ExecSQL('UPDATE Ingredients '
|
370 |
+ Format('SET NDF = %.15f ', [InputProximal(ValidateEditNDF.AsFloat, RapMS, ComboBoxFibre.ItemIndex div 2, ComboBoxFibre.ItemIndex mod 2)], USFormatSettings) |
371 |
+ Format('WHERE Id = %d', [NewId]));
|
372 |
if CheckBoxADF.Checked
|
373 |
then
|
374 |
DBUser.ExecSQL('UPDATE Ingredients '
|
375 |
+ Format('SET ADF = %.15f ', [InputProximal(ValidateEditADF.AsFloat, RapMS, ComboBoxFibre.ItemIndex div 2, ComboBoxFibre.ItemIndex mod 2)], USFormatSettings) |
376 |
+ Format('WHERE Id = %d', [NewId]));
|
377 |
if CheckBoxAmidon.Checked
|
378 |
then
|
379 |
DBUser.ExecSQL('UPDATE Ingredients '
|
380 |
+ Format('SET Amidon = %.15f ', [InputProximal(ValidateEditAmidon.AsFloat, RapMS, ComboBoxAmidon.ItemIndex div 2, ComboBoxAmidon.ItemIndex mod 2)], USFormatSettings) |
381 |
+ Format('WHERE Id = %d', [NewId]));
|
382 |
if CheckBoxSucres.Checked
|
383 |
then
|
384 |
DBUser.ExecSQL('UPDATE Ingredients '
|
385 |
+ Format('SET Sucres = %.15f ', [InputProximal(ValidateEditSucres.AsFloat, RapMS, ComboBoxSucres.ItemIndex div 2, ComboBoxSucres.ItemIndex mod 2)], USFormatSettings) |
386 |
+ Format('WHERE Id = %d', [NewId]));
|
387 |
end;
|
388 |
DBUser.Commit; |
389 |
except
|
390 |
DBUser.RollBack; |
391 |
MessageDlg(Format(_('Unknown error: %s %s %s'), ['UnitIngredientCreation', 'ActionOKExecute', 'DBUser (INSERT INTO Ingredients / UPDATE Ingredients)']), mtError, [mbOK], 0); |
392 |
Exit; |
393 |
end;
|
394 |
// Ajouter dans ClientDataSetIngredients
|
395 |
Application.ProcessMessages; |
396 |
TableIngredients := DBUser.GetTable('SELECT * FROM Ingredients '
|
397 |
+ Format('WHERE Id = %d', [NewId]));
|
398 |
ClientDataSetIngredients.Append; |
399 |
try
|
400 |
ClientDataSetIngredientsId.Value := NewId; |
401 |
ClientDataSetIngredientsName.Value := NewName; |
402 |
ClientDataSetIngredientsDefinition.Value := NewComment; |
403 |
ClientDataSetIngredientsClass.Value := ComboBoxClass.ItemIndex + 1;
|
404 |
ClientDataSetIngredientsUser.Value := True; |
405 |
if PageControlCreation.TabIndex = 0 |
406 |
then // Copie bas?e sur un mod?le |
407 |
begin
|
408 |
ClientDataSetIngredientsModel.Value := ValidateEditModel.AsInteger; |
409 |
ClientDataSetInraAfz.Locate('Id', ClientDataSetIngredientsModel.Value, []);
|
410 |
ClientDataSetIngredientsSource.Value := Format(_('Copy of "%s"'), [dgettext('InraAfz', WideString(ClientDataSetInraAfzName.Value))]); |
411 |
CalcCopy; |
412 |
end
|
413 |
else // Cr?ation originale |
414 |
begin
|
415 |
ClientDataSetIngredientsSource.Value := _('Original item');
|
416 |
CalcOriginal; |
417 |
end;
|
418 |
ClientDataSetIngredients.Post; |
419 |
except
|
420 |
ClientDataSetIngredients.Cancel; |
421 |
MessageDlg(Format(_('Unknown error: %s %s %s'), ['UnitIngredientCreation', 'ActionOKExecute', 'ClientDataSetIngredients']), mtError, [mbOK], 0); |
422 |
Exit; |
423 |
end;
|
424 |
TableIngredients.Free; |
425 |
// Ajouter le nom dans la liste des mati?res premi?res utilisateur
|
426 |
UserList.Add(NewName); |
427 |
end;
|
428 |
ModalResult := mrOk; |
429 |
end;
|
430 |
|
431 |
procedure TFormIngredientCreation.ButtonNextClick(Sender: TObject);
|
432 |
begin
|
433 |
if ValidateEditMSOriginal.Value = 0 |
434 |
then
|
435 |
begin
|
436 |
MessageDlg(_('You must specify a dry matter value for this ingredient.'), mtError, [mbOK], 0); |
437 |
ActiveControl := ValidateEditMSOriginal; |
438 |
end
|
439 |
else
|
440 |
begin
|
441 |
CheckBoxMM.Enabled := True; |
442 |
ComboBoxMM.Enabled := True; |
443 |
CheckBoxMAT.Enabled := True; |
444 |
ComboBoxMAT.Enabled := True; |
445 |
CheckBoxCB.Enabled := True; |
446 |
CheckBoxNDF.Enabled := True; |
447 |
CheckBoxADF.Enabled := True; |
448 |
ComboBoxFibre.Enabled := True; |
449 |
CheckBoxMG.Enabled := True; |
450 |
ComboBoxMG.Enabled := True; |
451 |
CheckBoxEB.Enabled := True; |
452 |
ComboBoxEB.Enabled := True; |
453 |
CheckBoxAmidon.Enabled := True; |
454 |
ComboBoxAmidon.Enabled := True; |
455 |
CheckBoxSucres.Enabled := True; |
456 |
ComboBoxSucres.Enabled := True; |
457 |
ActiveControl := CheckBoxMM; |
458 |
ValidateEditMSOriginal.Enabled := False; |
459 |
ComboBoxMSOriginal.Enabled := False; |
460 |
ButtonNext.Visible := False; |
461 |
end;
|
462 |
end;
|
463 |
|
464 |
procedure TFormIngredientCreation.CheckBoxADFClick(Sender: TObject);
|
465 |
begin
|
466 |
if CheckBoxADF.Checked
|
467 |
then // Activer la saisie |
468 |
EditActivate(ValidateEditADF) |
469 |
else // Valeur inconnue |
470 |
EditEmpty(ValidateEditADF); |
471 |
ComboBoxFibreChange(nil);
|
472 |
end;
|
473 |
|
474 |
procedure TFormIngredientCreation.CheckBoxAmidonClick(Sender: TObject);
|
475 |
begin
|
476 |
if CheckBoxAmidon.Checked
|
477 |
then // Activer la saisie |
478 |
EditActivate(ValidateEditAmidon) |
479 |
else // Valeur inconnue |
480 |
EditEmpty(ValidateEditAmidon); |
481 |
ComboBoxAmidonChange(nil);
|
482 |
end;
|
483 |
|
484 |
procedure TFormIngredientCreation.CheckBoxCBClick(Sender: TObject);
|
485 |
begin
|
486 |
if CheckBoxCB.Checked
|
487 |
then // Activer la saisie |
488 |
EditActivate(ValidateEditCB) |
489 |
else // Valeur inconnue |
490 |
EditEmpty(ValidateEditCB); |
491 |
ComboBoxFibreChange(nil);
|
492 |
end;
|
493 |
|
494 |
procedure TFormIngredientCreation.CheckBoxEBClick(Sender: TObject);
|
495 |
begin
|
496 |
if CheckBoxEB.Checked
|
497 |
then // Activer la saisie |
498 |
EditActivate(ValidateEditEB) |
499 |
else // Valeur inconnue |
500 |
EditEmpty(ValidateEditEB); |
501 |
ComboBoxEBChange(nil);
|
502 |
end;
|
503 |
|
504 |
procedure TFormIngredientCreation.CheckBoxMATClick(Sender: TObject);
|
505 |
begin
|
506 |
if CheckBoxMAT.Checked
|
507 |
then // Activer la saisie |
508 |
EditActivate(ValidateEditMAT) |
509 |
else // Valeur inconnue |
510 |
EditEmpty(ValidateEditMAT); |
511 |
ComboBoxMATChange(nil);
|
512 |
end;
|
513 |
|
514 |
procedure TFormIngredientCreation.CheckBoxMGClick(Sender: TObject);
|
515 |
begin
|
516 |
if CheckBoxMG.Checked
|
517 |
then // Activer la saisie |
518 |
EditActivate(ValidateEditMG) |
519 |
else // Valeur inconnue |
520 |
EditEmpty(ValidateEditMG); |
521 |
ComboBoxMGChange(nil);
|
522 |
end;
|
523 |
|
524 |
procedure TFormIngredientCreation.CheckBoxMMClick(Sender: TObject);
|
525 |
begin
|
526 |
if CheckBoxMM.Checked
|
527 |
then // Activer la saisie |
528 |
EditActivate(ValidateEditMM) |
529 |
else // Valeur inconnue |
530 |
EditEmpty(ValidateEditMM); |
531 |
ComboBoxMMChange(nil);
|
532 |
end;
|
533 |
|
534 |
procedure TFormIngredientCreation.CheckBoxNDFClick(Sender: TObject);
|
535 |
begin
|
536 |
if CheckBoxNDF.Checked
|
537 |
then // Activer la saisie |
538 |
EditActivate(ValidateEditNDF) |
539 |
else // Valeur inconnue |
540 |
EditEmpty(ValidateEditNDF); |
541 |
ComboBoxFibreChange(nil);
|
542 |
end;
|
543 |
|
544 |
procedure TFormIngredientCreation.CheckBoxSucresClick(Sender: TObject);
|
545 |
begin
|
546 |
if CheckBoxSucres.Checked
|
547 |
then // Activer la saisie |
548 |
EditActivate(ValidateEditSucres) |
549 |
else // Valeur inconnue |
550 |
EditEmpty(ValidateEditSucres); |
551 |
ComboBoxSucresChange(nil);
|
552 |
end;
|
553 |
|
554 |
procedure TFormIngredientCreation.ComboBoxAmidonChange(Sender: TObject);
|
555 |
begin
|
556 |
if ComboBoxAmidon.ItemIndex mod 2 = 0 |
557 |
then // % |
558 |
begin
|
559 |
ValidateEditAmidon.DecimalPlaces := 2;
|
560 |
ValidateEditAmidon.MaxValue := 100;
|
561 |
end
|
562 |
else // g/kg |
563 |
begin
|
564 |
ValidateEditAmidon.DecimalPlaces := 1;
|
565 |
ValidateEditAmidon.MaxValue := 1000;
|
566 |
end;
|
567 |
end;
|
568 |
|
569 |
procedure TFormIngredientCreation.ComboBoxClassChange(Sender: TObject);
|
570 |
var
|
571 |
Model: String;
|
572 |
begin
|
573 |
ModelList.Clear; |
574 |
with DataModuleDeclaration do |
575 |
begin
|
576 |
ClientDataSetInraAfz.Filtered := False; |
577 |
if ComboBoxClass.ItemIndex <> -1 |
578 |
then
|
579 |
begin
|
580 |
ClientDataSetInraAfz.Filter := Format('Class = %d', [ComboBoxClass.ItemIndex + 1]); |
581 |
ClientDataSetInraAfz.Filtered := True; |
582 |
end;
|
583 |
ClientDataSetInraAfz.First; |
584 |
while not ClientDataSetInraAfz.Eof do |
585 |
begin
|
586 |
ModelList.Add(dgettext('InraAfz', WideString(ClientDataSetInraAfzName.Value)));
|
587 |
ClientDataSetInraAfz.Next; |
588 |
end;
|
589 |
end;
|
590 |
Model := ComboBoxModel.Text; |
591 |
ComboBoxModel.Clear; |
592 |
ComboBoxModel.Items.Assign(ModelList); |
593 |
ComboBoxModel.ItemIndex := ComboBoxModel.Items.IndexOf(Model); |
594 |
end;
|
595 |
|
596 |
procedure TFormIngredientCreation.ComboBoxEBChange(Sender: TObject);
|
597 |
begin
|
598 |
if ComboBoxEB.ItemIndex mod 2 = 0 |
599 |
then // MJ/kg |
600 |
ValidateEditEB.DecimalPlaces := 2
|
601 |
else // kcal/kg |
602 |
ValidateEditEB.DecimalPlaces := 0;
|
603 |
end;
|
604 |
|
605 |
procedure TFormIngredientCreation.ComboBoxFibreChange(Sender: TObject);
|
606 |
begin
|
607 |
if ComboBoxFibre.ItemIndex mod 2 = 0 |
608 |
then // % |
609 |
begin
|
610 |
ValidateEditCB.DecimalPlaces := 2;
|
611 |
ValidateEditNDF.DecimalPlaces := 2;
|
612 |
ValidateEditADF.DecimalPlaces := 2;
|
613 |
ValidateEditCB.MaxValue := 100;
|
614 |
ValidateEditNDF.MaxValue := 100;
|
615 |
ValidateEditADF.MaxValue := 100;
|
616 |
end
|
617 |
else // g/kg |
618 |
begin
|
619 |
ValidateEditCB.DecimalPlaces := 1;
|
620 |
ValidateEditNDF.DecimalPlaces := 1;
|
621 |
ValidateEditADF.DecimalPlaces := 1;
|
622 |
ValidateEditCB.MaxValue := 1000;
|
623 |
ValidateEditNDF.MaxValue := 1000;
|
624 |
ValidateEditADF.MaxValue := 1000;
|
625 |
end;
|
626 |
end;
|
627 |
|
628 |
procedure TFormIngredientCreation.ComboBoxMATChange(Sender: TObject);
|
629 |
begin
|
630 |
if ComboBoxMAT.ItemIndex mod 2 = 0 |
631 |
then // % |
632 |
begin
|
633 |
ValidateEditMAT.DecimalPlaces := 2;
|
634 |
ValidateEditMAT.MaxValue := 100;
|
635 |
end
|
636 |
else // g/kg |
637 |
begin
|
638 |
ValidateEditMAT.DecimalPlaces := 1;
|
639 |
ValidateEditMAT.MaxValue := 1000;
|
640 |
end;
|
641 |
end;
|
642 |
|
643 |
procedure TFormIngredientCreation.ComboBoxMGChange(Sender: TObject);
|
644 |
begin
|
645 |
if ComboBoxMG.ItemIndex mod 2 = 0 |
646 |
then // % |
647 |
begin
|
648 |
ValidateEditMG.DecimalPlaces := 2;
|
649 |
ValidateEditMG.MaxValue := 100;
|
650 |
end
|
651 |
else // g/kg |
652 |
begin
|
653 |
ValidateEditMG.DecimalPlaces := 1;
|
654 |
ValidateEditMG.MaxValue := 1000;
|
655 |
end;
|
656 |
end;
|
657 |
|
658 |
procedure TFormIngredientCreation.ComboBoxMMChange(Sender: TObject);
|
659 |
begin
|
660 |
if ComboBoxMM.ItemIndex mod 2 = 0 |
661 |
then // % |
662 |
begin
|
663 |
ValidateEditMM.DecimalPlaces := 2;
|
664 |
ValidateEditMM.MaxValue := 100;
|
665 |
end
|
666 |
else // g/kg |
667 |
begin
|
668 |
ValidateEditMM.DecimalPlaces := 1;
|
669 |
ValidateEditMM.MaxValue := 1000;
|
670 |
end;
|
671 |
end;
|
672 |
|
673 |
procedure TFormIngredientCreation.ComboBoxModelChange(Sender: TObject);
|
674 |
begin
|
675 |
if ComboBoxModel.ItemIndex <> -1 |
676 |
then
|
677 |
with DataModuleDeclaration do |
678 |
begin
|
679 |
ClientDataSetInraAfz.RecNo := ModelList.IndexOf(ComboBoxModel.Text) + 1;
|
680 |
ValidateEditModel.AsInteger := ClientDataSetInraAfzId.Value; |
681 |
ValidateEditMSCopy.AsFloat := OutputProximal(ClientDataSetInraAfzMS.Value, 1, 1, FormOptions.Proximal); |
682 |
ComboBoxClass.ItemIndex := ClientDataSetInraAfzClass.Value - 1;
|
683 |
ComboBoxClassChange(nil);
|
684 |
end;
|
685 |
end;
|
686 |
|
687 |
procedure TFormIngredientCreation.ComboBoxMSCopyChange(Sender: TObject);
|
688 |
begin
|
689 |
if ComboBoxMSCopy.ItemIndex = 0 |
690 |
then // % |
691 |
begin
|
692 |
ValidateEditMSCopy.DecimalPlaces := 2;
|
693 |
ValidateEditMSCopy.MaxValue := 100;
|
694 |
end
|
695 |
else // g/kg |
696 |
begin
|
697 |
ValidateEditMSCopy.DecimalPlaces := 1;
|
698 |
ValidateEditMSCopy.MaxValue := 1000;
|
699 |
end;
|
700 |
end;
|
701 |
|
702 |
procedure TFormIngredientCreation.ComboBoxMSOriginalChange(Sender: TObject);
|
703 |
begin
|
704 |
if ComboBoxMSOriginal.ItemIndex = 0 |
705 |
then // % |
706 |
begin
|
707 |
ValidateEditMSOriginal.DecimalPlaces := 2;
|
708 |
ValidateEditMSOriginal.MaxValue := 100;
|
709 |
end
|
710 |
else // g/kg |
711 |
begin
|
712 |
ValidateEditMSOriginal.DecimalPlaces := 1;
|
713 |
ValidateEditMSOriginal.MaxValue := 1000;
|
714 |
end;
|
715 |
end;
|
716 |
|
717 |
procedure TFormIngredientCreation.ComboBoxSucresChange(Sender: TObject);
|
718 |
begin
|
719 |
if ComboBoxSucres.ItemIndex mod 2 = 0 |
720 |
then // % |
721 |
begin
|
722 |
ValidateEditSucres.DecimalPlaces := 2;
|
723 |
ValidateEditSucres.MaxValue := 100;
|
724 |
end
|
725 |
else // g/kg |
726 |
begin
|
727 |
ValidateEditSucres.DecimalPlaces := 1;
|
728 |
ValidateEditSucres.MaxValue := 1000;
|
729 |
end;
|
730 |
end;
|
731 |
|
732 |
procedure TFormIngredientCreation.EditActivate(Edit: TJvValidateEdit);
|
733 |
begin
|
734 |
Edit.DisplayFormat := dfFloat; |
735 |
Edit.Enabled := True; |
736 |
ActiveControl := Edit; |
737 |
Edit.SelectAll; |
738 |
end;
|
739 |
|
740 |
procedure TFormIngredientCreation.EditEmpty(Edit: TJvValidateEdit);
|
741 |
begin
|
742 |
Edit.DisplayFormat := dfNone; |
743 |
Edit.Value := '';
|
744 |
Edit.Enabled := False; |
745 |
end;
|
746 |
|
747 |
procedure TFormIngredientCreation.FormCreate(Sender: TObject);
|
748 |
var
|
749 |
i: Integer; |
750 |
begin
|
751 |
if Screen.Fonts.IndexOf('Arial Unicode MS') <> -1 |
752 |
then
|
753 |
Font.Name := 'Arial Unicode MS';
|
754 |
// PanelButtons.Font.Size := PanelButtons.Font.Size + 2;
|
755 |
PanelButtons.Font.Style := [fsBold]; |
756 |
LabelName.Font.Style := [fsBold]; |
757 |
EditName.Font.Style := [fsBold]; |
758 |
LabelMSCopyWarning.Font.Color := clRed; |
759 |
LabelMSOriginalWarning.Font.Color := clRed; |
760 |
TranslateComponent(Self); |
761 |
ComboBoxMSCopy.ItemIndex := FormOptions.Proximal; |
762 |
ComboBoxMSCopyChange(nil);
|
763 |
ComboBoxMSOriginal.ItemIndex := FormOptions.Proximal; |
764 |
ComboBoxMSOriginalChange(nil);
|
765 |
for i := 0 to FormOptions.ComboBoxProximal.Items.Count - 1 do |
766 |
ComboBoxMM.Items.Add(Format('%s %s', [FormOptions.ComboBoxProximal.Items[i], _('DM')])); |
767 |
ComboBoxMM.ItemIndex := FormOptions.Proximal + 2 * FormOptions.Expression;
|
768 |
ComboBoxMMChange(nil);
|
769 |
for i := 0 to FormOptions.ComboBoxProximal.Items.Count - 1 do |
770 |
ComboBoxMAT.Items.Add(Format('%s %s', [FormOptions.ComboBoxProximal.Items[i], _('DM')])); |
771 |
ComboBoxMAT.ItemIndex := FormOptions.Proximal + 2 * FormOptions.Expression;
|
772 |
ComboBoxMATChange(nil);
|
773 |
for i := 0 to FormOptions.ComboBoxProximal.Items.Count - 1 do |
774 |
ComboBoxMG.Items.Add(Format('%s %s', [FormOptions.ComboBoxProximal.Items[i], _('DM')])); |
775 |
ComboBoxMG.ItemIndex := FormOptions.Proximal + 2 * FormOptions.Expression;
|
776 |
ComboBoxMGChange(nil);
|
777 |
for i := 0 to FormOptions.ComboBoxEnergy.Items.Count - 1 do |
778 |
ComboBoxEB.Items.Add(Format('%s %s', [FormOptions.ComboBoxEnergy.Items[i], _('DM')])); |
779 |
ComboBoxEB.ItemIndex := FormOptions.Energy + 2 * FormOptions.Expression;
|
780 |
ComboBoxEBChange(nil);
|
781 |
for i := 0 to FormOptions.ComboBoxProximal.Items.Count - 1 do |
782 |
ComboBoxFibre.Items.Add(Format('%s %s', [FormOptions.ComboBoxProximal.Items[i], _('DM')])); |
783 |
ComboBoxFibre.ItemIndex := FormOptions.Proximal + 2 * FormOptions.Expression;
|
784 |
ComboBoxFibreChange(nil);
|
785 |
for i := 0 to FormOptions.ComboBoxProximal.Items.Count - 1 do |
786 |
ComboBoxAmidon.Items.Add(Format('%s %s', [FormOptions.ComboBoxProximal.Items[i], _('DM')])); |
787 |
ComboBoxAmidon.ItemIndex := FormOptions.Proximal + 2 * FormOptions.Expression;
|
788 |
ComboBoxAmidonChange(nil);
|
789 |
for i := 0 to FormOptions.ComboBoxProximal.Items.Count - 1 do |
790 |
ComboBoxSucres.Items.Add(Format('%s %s', [FormOptions.ComboBoxProximal.Items[i], _('DM')])); |
791 |
ComboBoxSucres.ItemIndex := FormOptions.Proximal + 2 * FormOptions.Expression;
|
792 |
ComboBoxSucresChange(nil);
|
793 |
ModelList := TStringList.Create; |
794 |
with DataModuleDeclaration do |
795 |
begin
|
796 |
// Classes
|
797 |
ClientDataSetClasses.First; |
798 |
while not ClientDataSetClasses.Eof do |
799 |
begin
|
800 |
ComboBoxClass.Items.Add(ClientDataSetClassesName.Value); |
801 |
ClientDataSetClasses.Next; |
802 |
end;
|
803 |
ComboBoxClassChange(nil); // Contruction de la liste des mod?les |
804 |
// Mod?le
|
805 |
if not ClientDataSetIngredientsUser.Value |
806 |
then // Pr?s?lectionner l'enregistrement courant |
807 |
begin
|
808 |
ComboBoxModel.ItemIndex := ComboBoxModel.Items.IndexOf(ClientDataSetIngredientsName.Value); |
809 |
ComboBoxModelChange(nil);
|
810 |
end;
|
811 |
end;
|
812 |
PageControlCreation.TabIndex := 0;
|
813 |
ActiveControl := EditName; |
814 |
end;
|
815 |
|
816 |
procedure TFormIngredientCreation.FormDestroy(Sender: TObject);
|
817 |
begin
|
818 |
with DataModuleDeclaration do |
819 |
ClientDataSetInraAfz.Filtered := False; |
820 |
end;
|
821 |
|
822 |
procedure TFormIngredientCreation.NumEditKeyDown(Sender: TObject;
|
823 |
var Key: Word; Shift: TShiftState);
|
824 |
begin
|
825 |
// D?tection de l'appui sur le s?parateur d?cimal du pav? num?rique
|
826 |
VK_Separator := (Key = VK_DECIMAL); |
827 |
end;
|
828 |
|
829 |
procedure TFormIngredientCreation.NumEditKeyPress(Sender: TObject;
|
830 |
var Key: Char);
|
831 |
begin
|
832 |
if VK_Separator then |
833 |
// Renvoyer le s?parateur d?cimal des options r?gionales et linguistiques
|
834 |
Key := DecimalSeparator; |
835 |
end;
|
836 |
|
837 |
end.
|