root / InraAfz / UFInraAfz.pas @ 1
Historique | Voir | Annoter | Télécharger (10,381 ko)
1 | 1 | avalancogn | unit UFInraAfz;
|
---|---|---|---|
2 | |||
3 | interface
|
||
4 | |||
5 | uses
|
||
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
||
7 | Dialogs, Grids, StdCtrls; |
||
8 | |||
9 | type
|
||
10 | TFInraAfz = class(TForm)
|
||
11 | ODInraAfz: TOpenDialog; |
||
12 | SGInraAfz: TStringGrid; |
||
13 | LBInraAfz: TListBox; |
||
14 | procedure FormShow(Sender: TObject);
|
||
15 | procedure FormClose(Sender: TObject; var Action: TCloseAction); |
||
16 | private
|
||
17 | { D?clarations priv?es }
|
||
18 | public
|
||
19 | { D?clarations publiques }
|
||
20 | end;
|
||
21 | |||
22 | var
|
||
23 | FInraAfz: TFInraAfz; |
||
24 | |||
25 | implementation
|
||
26 | |||
27 | {$R *.dfm}
|
||
28 | |||
29 | const
|
||
30 | NFicMatInraAfz = 'InraAfz.rec';
|
||
31 | MAX_MP = 50;
|
||
32 | |||
33 | type
|
||
34 | CompositionChimique = record
|
||
35 | MS, MM, MO, Lip, MAT, Amidon, Sucres, |
||
36 | dMO_T, dMO_C, dLip_T, dLip_C, dMAT_T, dMAT_C, |
||
37 | EB, ED_T, ED_C, EM_T, EM_C, EN_T, EN_C, |
||
38 | Ca, P, Na, K, Cl, Mg, Cu, Zn, Fe, Mn, S, Se, Co, Mb, I, |
||
39 | Phytase, ActPhytE, ActPhytM, PdigG, PdigF, |
||
40 | C6C8C10, C12_0, C14_0, C16_0, C16_1, C18_0, C18_1, C18_2, C18_3, C18_4, |
||
41 | C20_0, C20_1, C20_4, C20_5, C22_0, C22_1, C22_5, C22_6, C24_0, AGsLip, |
||
42 | CB, dCB_T, dCB_C, Residu, dResidu_T, dResidu_C, |
||
43 | NDF, ADF, ADL, Parois: Double; |
||
44 | end;
|
||
45 | RecMatiere = record
|
||
46 | Num: Integer; |
||
47 | Nom: string[35]; |
||
48 | Memo: string[255]; |
||
49 | Typ: Integer; |
||
50 | CC: CompositionChimique; |
||
51 | AAtotal, CUDAA: array[0..12] of Double; |
||
52 | end;
|
||
53 | PRecMatiere = ^RecMatiere; |
||
54 | |||
55 | var
|
||
56 | PMatiere: PRecMatiere; |
||
57 | ListMatiere: TList; |
||
58 | |||
59 | procedure TFInraAfz.FormShow(Sender: TObject);
|
||
60 | var
|
||
61 | i, lig, col: Integer; |
||
62 | ok: Boolean; |
||
63 | s: string;
|
||
64 | sep: Char; |
||
65 | F: TextFile; |
||
66 | |||
67 | function GetInteger(var I: Integer; var Ch: Char): Boolean; |
||
68 | var
|
||
69 | S: string;
|
||
70 | Fin: boolean; |
||
71 | begin
|
||
72 | S := '';
|
||
73 | Read(F, Ch);
|
||
74 | Fin := (Ch = ';') or (Ch = Chr(13)) or (Ch = Chr(26)); |
||
75 | while not Fin do |
||
76 | begin
|
||
77 | S := S + Ch; |
||
78 | Read(F, Ch);
|
||
79 | Fin := (Ch = ';') or (Ch = Chr(13)) or (Ch = Chr(26)); |
||
80 | end ;
|
||
81 | S := Trim(S); |
||
82 | result := TRUE ; |
||
83 | if Length(S) = 0 |
||
84 | then
|
||
85 | I := 0
|
||
86 | else
|
||
87 | try
|
||
88 | I := StrToInt(S); |
||
89 | except
|
||
90 | result := FALSE; |
||
91 | end;
|
||
92 | end;
|
||
93 | |||
94 | function GetDouble(var D: Double; var Ch: Char): Boolean; |
||
95 | var
|
||
96 | S: string;
|
||
97 | Fin: boolean; |
||
98 | begin
|
||
99 | S := '';
|
||
100 | Read(F, Ch);
|
||
101 | Fin := (Ch = ';') or (Ch = Chr(13)) or (Ch = Chr(26)); |
||
102 | while not Fin do |
||
103 | begin
|
||
104 | S := S + Ch; |
||
105 | Read(F, Ch);
|
||
106 | Fin := (Ch = ';') or (Ch = Chr(13)) or (Ch = Chr(26)); |
||
107 | end ;
|
||
108 | S := Trim(S); |
||
109 | result := TRUE; |
||
110 | if Length(S) = 0 |
||
111 | then
|
||
112 | D := 0
|
||
113 | else
|
||
114 | try
|
||
115 | D := StrToFloat(S); |
||
116 | except
|
||
117 | result := FALSE; |
||
118 | end;
|
||
119 | end;
|
||
120 | |||
121 | function GetString(var S: string; var Ch: Char): Boolean; |
||
122 | var
|
||
123 | Fin, Quoted: boolean; |
||
124 | begin
|
||
125 | S := '';
|
||
126 | Read(F, Ch);
|
||
127 | Fin := (Ch = ';') or (Ch = Chr(13)) or (Ch = Chr(26)); |
||
128 | Quoted := (Ch = '"');
|
||
129 | if Quoted
|
||
130 | then
|
||
131 | begin
|
||
132 | Read(F, Ch);
|
||
133 | Fin := (Ch = Chr(26));
|
||
134 | while not Fin do |
||
135 | begin
|
||
136 | if (Ch = '"') |
||
137 | then
|
||
138 | begin
|
||
139 | Read (F, Ch);
|
||
140 | Fin := (Ch <> '"');
|
||
141 | Quoted := not ((Ch = ';') or (Ch = Chr(13)) or (Ch = Chr(26))); |
||
142 | end;
|
||
143 | if not Fin |
||
144 | then
|
||
145 | begin
|
||
146 | S := S + Ch; |
||
147 | Read(F, Ch);
|
||
148 | Fin := (Ch = Chr(26));
|
||
149 | end;
|
||
150 | end;
|
||
151 | end
|
||
152 | else
|
||
153 | while not Fin do |
||
154 | begin
|
||
155 | S := S + Ch; |
||
156 | Read(F, Ch);
|
||
157 | Fin := (Ch = ';') or (Ch = Chr(13)) or (Ch = Chr(26)); |
||
158 | end;
|
||
159 | result := not Quoted;
|
||
160 | end;
|
||
161 | |||
162 | // FormShow
|
||
163 | begin
|
||
164 | ListMatiere := TList.Create; |
||
165 | SetCurrentDir(ExtractFilePath(Application.ExeName)); |
||
166 | ODInraAfz.InitialDir := GetCurrentDir; |
||
167 | ODInraAfz.FileName := ChangeFileExt(NFicMatInraAfz, '.csv');
|
||
168 | {
|
||
169 | SGInraAfz.ColCount := LBInraAfz.Count;
|
||
170 | for i := 0 to LBInraAfz.Count - 1 do
|
||
171 | SGInraAfz.Cells[i, 0] := LBInraAfz.Items[i];
|
||
172 | }
|
||
173 | SGInraAfz.Cells[0, 0] := 'N?'; |
||
174 | SGInraAfz.Cells[1, 0] := 'Nom'; |
||
175 | if ODInraAfz.Execute
|
||
176 | then
|
||
177 | begin
|
||
178 | AssignFile(F, ODInraAfz.FileName); |
||
179 | Reset(F); |
||
180 | if Eof(F)
|
||
181 | then // Le fichier est vide |
||
182 | begin
|
||
183 | CloseFile(F); |
||
184 | Exit; |
||
185 | end;
|
||
186 | Readln(F, s); // Lecture de la ligne de titre
|
||
187 | if Eof(F)
|
||
188 | then // Il n'y a pas d'enregistrement |
||
189 | begin
|
||
190 | CloseFile(F); |
||
191 | Exit; |
||
192 | end;
|
||
193 | lig := 1;
|
||
194 | col := 1;
|
||
195 | New(PMatiere); |
||
196 | repeat
|
||
197 | ok := TRUE; |
||
198 | case col of |
||
199 | 1: // Nom |
||
200 | begin
|
||
201 | ok := GetString(s, sep); |
||
202 | if ok then PMatiere.Nom := Trim(s); |
||
203 | end;
|
||
204 | 2: // Commentaire |
||
205 | begin
|
||
206 | ok := GetString(s, sep); |
||
207 | if ok then PMatiere.Memo := s; |
||
208 | end ;
|
||
209 | 3: ok := GetInteger(PMatiere.Typ, sep);
|
||
210 | 4: ok := GetDouble(PMatiere.CC.MS, sep);
|
||
211 | 5: ok := GetDouble(PMatiere.CC.MM, sep);
|
||
212 | 6: ok := GetDouble(PMatiere.CC.MO, sep);
|
||
213 | 7: ok := GetDouble(PMatiere.CC.Lip, sep);
|
||
214 | 8: ok := GetDouble(PMatiere.CC.MAT, sep);
|
||
215 | 9: ok := GetDouble(PMatiere.CC.Amidon, sep);
|
||
216 | 10: ok := GetDouble(PMatiere.CC.Sucres, sep);
|
||
217 | 11: ok := GetDouble(PMatiere.CC.dMO_T, sep);
|
||
218 | 12: ok := GetDouble(PMatiere.CC.dMO_C, sep);
|
||
219 | 13: ok := GetDouble(PMatiere.CC.dLip_T, sep);
|
||
220 | 14: ok := GetDouble(PMatiere.CC.dLip_C, sep);
|
||
221 | 15: ok := GetDouble(PMatiere.CC.dMAT_T, sep);
|
||
222 | 16: ok := GetDouble(PMatiere.CC.dMAT_C, sep);
|
||
223 | 17: ok := GetDouble(PMatiere.CC.EB, sep);
|
||
224 | 18: ok := GetDouble(PMatiere.CC.ED_T, sep);
|
||
225 | 19: ok := GetDouble(PMatiere.CC.ED_C, sep);
|
||
226 | 20: ok := GetDouble(PMatiere.CC.EM_T, sep);
|
||
227 | 21: ok := GetDouble(PMatiere.CC.EM_C, sep);
|
||
228 | 22: ok := GetDouble(PMatiere.CC.EN_T, sep);
|
||
229 | 23: ok := GetDouble(PMatiere.CC.EN_C, sep);
|
||
230 | 24: ok := GetDouble(PMatiere.CC.Ca, sep);
|
||
231 | 25: ok := GetDouble(PMatiere.CC.P, sep);
|
||
232 | 26: ok := GetDouble(PMatiere.CC.Na, sep);
|
||
233 | 27: ok := GetDouble(PMatiere.CC.K, sep);
|
||
234 | 28: ok := GetDouble(PMatiere.CC.Mg, sep);
|
||
235 | 29: ok := GetDouble(PMatiere.CC.Cl, sep);
|
||
236 | 30: ok := GetDouble(PMatiere.CC.S, sep);
|
||
237 | 31: ok := GetDouble(PMatiere.CC.Cu, sep);
|
||
238 | 32: ok := GetDouble(PMatiere.CC.Zn, sep);
|
||
239 | 33: ok := GetDouble(PMatiere.CC.Mn, sep);
|
||
240 | 34: ok := GetDouble(PMatiere.CC.Fe, sep);
|
||
241 | 35: ok := GetDouble(PMatiere.CC.Se, sep);
|
||
242 | 36: ok := GetDouble(PMatiere.CC.Co, sep);
|
||
243 | 37: ok := GetDouble(PMatiere.CC.Mb, sep);
|
||
244 | 38: ok := GetDouble(PMatiere.CC.I, sep);
|
||
245 | 39: ok := GetDouble(PMatiere.CC.PdigG, sep);
|
||
246 | 40: ok := GetDouble(PMatiere.CC.PdigF, sep);
|
||
247 | 41: ok := GetDouble(PMatiere.CC.Phytase, sep);
|
||
248 | 42: ok := GetDouble(PMatiere.CC.ActPhytE, sep);
|
||
249 | 43: ok := GetDouble(PMatiere.CC.ActPhytM, sep);
|
||
250 | 44: ok := GetDouble(PMatiere.CC.C6C8C10, sep);
|
||
251 | 45: ok := GetDouble(PMatiere.CC.C12_0, sep);
|
||
252 | 46: ok := GetDouble(PMatiere.CC.C14_0, sep);
|
||
253 | 47: ok := GetDouble(PMatiere.CC.C16_0, sep);
|
||
254 | 48: ok := GetDouble(PMatiere.CC.C16_1, sep);
|
||
255 | 49: ok := GetDouble(PMatiere.CC.C18_0, sep);
|
||
256 | 50: ok := GetDouble(PMatiere.CC.C18_1, sep);
|
||
257 | 51: ok := GetDouble(PMatiere.CC.C18_2, sep);
|
||
258 | 52: ok := GetDouble(PMatiere.CC.C18_3, sep);
|
||
259 | 53: ok := GetDouble(PMatiere.CC.C18_4, sep);
|
||
260 | 54: ok := GetDouble(PMatiere.CC.C20_0, sep);
|
||
261 | 55: ok := GetDouble(PMatiere.CC.C20_1, sep);
|
||
262 | 56: ok := GetDouble(PMatiere.CC.C20_4, sep);
|
||
263 | 57: ok := GetDouble(PMatiere.CC.C20_5, sep);
|
||
264 | 58: ok := GetDouble(PMatiere.CC.C22_0, sep);
|
||
265 | 59: ok := GetDouble(PMatiere.CC.C22_1, sep);
|
||
266 | 60: ok := GetDouble(PMatiere.CC.C22_5, sep);
|
||
267 | 61: ok := GetDouble(PMatiere.CC.C22_6, sep);
|
||
268 | 62: ok := GetDouble(PMatiere.CC.C24_0, sep);
|
||
269 | 63: ok := GetDouble(PMatiere.CC.AGsLip, sep);
|
||
270 | 64: ok := GetDouble(PMatiere.CC.CB, sep);
|
||
271 | 65: ok := GetDouble(PMatiere.CC.dCB_T, sep);
|
||
272 | 66: ok := GetDouble(PMatiere.CC.dCB_C, sep);
|
||
273 | 67: ok := GetDouble(PMatiere.CC.Residu, sep);
|
||
274 | 68: ok := GetDouble(PMatiere.CC.dResidu_T, sep);
|
||
275 | 69: ok := GetDouble(PMatiere.CC.dResidu_C, sep);
|
||
276 | 70: ok := GetDouble(PMatiere.CC.NDF, sep);
|
||
277 | 71: ok := GetDouble(PMatiere.CC.ADF, sep);
|
||
278 | 72: ok := GetDouble(PMatiere.CC.ADL, sep);
|
||
279 | 73: ok := GetDouble(PMatiere.CC.Parois, sep);
|
||
280 | 74..85: ok := GetDouble(PMatiere.AAtotal[col - 73], sep); |
||
281 | 86..98: ok := GetDouble(PMatiere.CUDAA[col - 86], sep); |
||
282 | end;
|
||
283 | if not ok then Break; |
||
284 | if (col = 98) or ((col = 1) and (Length(PMatiere.Nom) = 0)) |
||
285 | then // Dernier champs ou ligne vide |
||
286 | ok := (sep = Chr(13)) or (sep = Chr(26)) |
||
287 | else
|
||
288 | ok := (sep = ';');
|
||
289 | if not ok then Break; |
||
290 | if sep = Chr(13) then Read(F, sep); // Chr (10) |
||
291 | if col = 98 |
||
292 | then // Passage ? la ligne suivante |
||
293 | begin
|
||
294 | PMatiere.AAtotal[0] := PMatiere.CC.MAT;
|
||
295 | ListMatiere.Add(PMatiere); |
||
296 | PMatiere.Num := - ListMatiere.Count; |
||
297 | New(PMatiere); |
||
298 | Inc(lig); |
||
299 | col := 1;
|
||
300 | end
|
||
301 | else
|
||
302 | if (col > 1) or (Length(PMatiere.Nom) > 0) |
||
303 | then // Passage au champs suivant |
||
304 | Inc(col); |
||
305 | until sep = Chr(26); // Eof (f) |
||
306 | Dispose(PMatiere); |
||
307 | CloseFile(F); |
||
308 | if not ok |
||
309 | then // erreur de lecture |
||
310 | MessageDlg(Format('Erreur ! (%d, %d)', [col, lig]), mtError, [mbOk], 0) |
||
311 | else // affichage du tableau |
||
312 | begin
|
||
313 | SGInraAfz.RowCount := ListMatiere.Count + 2;
|
||
314 | for i := 1 to ListMatiere.Count do |
||
315 | begin
|
||
316 | PMatiere := ListMatiere.Items[i - 1];
|
||
317 | SGInraAfz.Cells[0, i] := IntToStr(PMatiere.Num);
|
||
318 | SGInraAfz.Cells[1, i] := PMatiere.Nom;
|
||
319 | end;
|
||
320 | end;
|
||
321 | end;
|
||
322 | end;
|
||
323 | |||
324 | procedure TFInraAfz.FormClose(Sender: TObject; var Action: TCloseAction); |
||
325 | var
|
||
326 | i: Integer; |
||
327 | fic: file of RecMatiere; |
||
328 | begin
|
||
329 | if SGInraAfz.RowCount > 2 |
||
330 | then // Enregistrement(s) pr?sent(s) |
||
331 | if MessageDlg('Enregistrer ?', mtWarning, [mbYes, mbNo], 0) = mrYes |
||
332 | then // Sauvegarder |
||
333 | begin
|
||
334 | AssignFile(fic, NFicMatInraAfz); |
||
335 | Rewrite(fic); |
||
336 | for i := 0 to ListMatiere.Count - 1 do |
||
337 | begin
|
||
338 | PMatiere := ListMatiere[i]; |
||
339 | Write(fic, PMatiere^);
|
||
340 | end ;
|
||
341 | CloseFile(fic); |
||
342 | end;
|
||
343 | if ListMatiere.Count > 0 |
||
344 | then
|
||
345 | for i := 0 to ListMatiere.Count - 1 do |
||
346 | begin
|
||
347 | PMatiere := ListMatiere[i]; |
||
348 | Dispose(PMatiere); |
||
349 | end;
|
||
350 | ListMatiere.Free; |
||
351 | end;
|
||
352 | |||
353 | end. |