root / UInit.pas
Historique | Voir | Annoter | Télécharger (67,427 ko)
1 | 3 | avalancogn | unit UInit;
|
---|---|---|---|
2 | |||
3 | interface
|
||
4 | |||
5 | uses
|
||
6 | Forms, Windows, Classes, StdCtrls, Dialogs, SysUtils, Types, UVariables, |
||
7 | Controls, gnugettext; |
||
8 | |||
9 | // Licence
|
||
10 | procedure InitLicense;
|
||
11 | procedure LoadLicense;
|
||
12 | procedure SaveLicense;
|
||
13 | procedure LoadLicFile(FileName: string); |
||
14 | procedure SaveLicFile(FileName: string); |
||
15 | // Configuration
|
||
16 | procedure LoadConfig;
|
||
17 | procedure SaveConfig;
|
||
18 | // Donn?es
|
||
19 | procedure InitData;
|
||
20 | procedure FreeData;
|
||
21 | procedure LoadData;
|
||
22 | procedure SaveData;
|
||
23 | // Mati?re premi?re
|
||
24 | procedure InitMatiere;
|
||
25 | procedure FreeMatiere;
|
||
26 | procedure LoadMatiere;
|
||
27 | procedure SaveMatiere;
|
||
28 | function MatiereUsed(Numero: integer): boolean;
|
||
29 | function MatiereFound(Numero: integer): boolean;
|
||
30 | function MatiereValid(rec: PRecMatiere): boolean;
|
||
31 | procedure StringsMatiere(Liste: TStrings; TypeMatiere: Integer;
|
||
32 | IncludeInvalid, IncludeInraAfz: Boolean); |
||
33 | // Aliment
|
||
34 | procedure InitAliment;
|
||
35 | procedure FreeAliment;
|
||
36 | procedure LoadAliment;
|
||
37 | procedure SaveAliment;
|
||
38 | function AlimentUsed(Numero: integer): boolean;
|
||
39 | function AlimentFound(Numero: integer): boolean;
|
||
40 | function AlimentValid(rec: PRecAliment): boolean;
|
||
41 | procedure StringsAliment(Liste: TStrings; TypeAliment: Integer;
|
||
42 | IncludeInvalid: Boolean); |
||
43 | // S?quence alimentaire truie
|
||
44 | procedure InitSeqAliT;
|
||
45 | procedure FreeSeqAliT;
|
||
46 | procedure LoadSeqAliT;
|
||
47 | procedure SaveSeqAliT;
|
||
48 | function SeqAliTUsed (Numero : integer) : boolean ;
|
||
49 | function SeqAliTFound (Numero : integer) : boolean ;
|
||
50 | function SeqAliTValid (rec : PRecSeqAliT) : boolean ;
|
||
51 | procedure StringsSeqAliT (Liste : TStrings ; IncludeInvalid : Boolean) ;
|
||
52 | // Plan de rationnement truie
|
||
53 | procedure InitRationT;
|
||
54 | procedure FreeRationT;
|
||
55 | procedure LoadRationT;
|
||
56 | procedure SaveRationT;
|
||
57 | function RationTUsed(Numero: integer): boolean;
|
||
58 | function RationTFound(Numero: integer): boolean;
|
||
59 | function RationTValid(rec: PRecRationT): boolean;
|
||
60 | procedure StringsRationT(Liste: TStrings; IncludeInvalid: Boolean);
|
||
61 | // Logement truie
|
||
62 | procedure InitLogeT;
|
||
63 | procedure FreeLogeT;
|
||
64 | procedure LoadLogeT;
|
||
65 | procedure SaveLogeT;
|
||
66 | function LogeTUsed(Numero: integer): boolean;
|
||
67 | function LogeTFound(Numero: integer): boolean;
|
||
68 | function LogeTValid(rec: PRecLogeT): boolean;
|
||
69 | procedure StringsLogeT(Liste: TStrings; IncludeInvalid: Boolean);
|
||
70 | // Profil truie
|
||
71 | procedure InitProfilT;
|
||
72 | procedure FreeProfilT;
|
||
73 | procedure LoadProfilT;
|
||
74 | procedure SaveProfilT;
|
||
75 | function ProfilTUsed(Numero: integer): boolean;
|
||
76 | function ProfilTFound(Numero: integer): boolean;
|
||
77 | function ProfilTValid(rec: PRecProfilT): boolean;
|
||
78 | procedure StringsProfilT(Liste: TStrings; IncludeInvalid: Boolean);
|
||
79 | // Simulation truie
|
||
80 | procedure InitSimulT;
|
||
81 | procedure FreeSimulT;
|
||
82 | procedure LoadSimulT;
|
||
83 | procedure SaveSimulT;
|
||
84 | function SimulTValid(rec: PRecSimulT): boolean;
|
||
85 | procedure StringsSimulT(Liste: TStrings; IncludeInvalid: Boolean);
|
||
86 | // S?quence alimentaire porc
|
||
87 | procedure InitSeqAliP;
|
||
88 | procedure FreeSeqAliP;
|
||
89 | procedure LoadSeqAliP;
|
||
90 | procedure SaveSeqAliP;
|
||
91 | function SeqAliPUsed(Numero: integer): boolean;
|
||
92 | function SeqAliPFound(Numero: integer): boolean;
|
||
93 | function SeqAliPValid(rec: PRecSeqAliP): boolean;
|
||
94 | procedure StringsSeqAliP(Liste: TStrings; IncludeInvalid: Boolean);
|
||
95 | // Plan de rationnement porc
|
||
96 | procedure InitRationP;
|
||
97 | procedure FreeRationP;
|
||
98 | procedure ConvertRationP2;
|
||
99 | procedure LoadRationP;
|
||
100 | procedure SaveRationP;
|
||
101 | function RationPUsed(Numero: integer): boolean;
|
||
102 | function RationPFound(Numero: integer): boolean;
|
||
103 | function RationPValid(rec: PRecRationP): boolean;
|
||
104 | procedure StringsRationP(Liste: TStrings; IncludeInvalid: Boolean);
|
||
105 | // Profil porc
|
||
106 | procedure InitProfilP;
|
||
107 | procedure FreeProfilP;
|
||
108 | procedure ConvertProfilP2;
|
||
109 | procedure LoadProfilP;
|
||
110 | procedure SaveProfilP;
|
||
111 | function ProfilPUsed(Numero: integer): boolean;
|
||
112 | function ProfilPFound(Numero: integer): boolean;
|
||
113 | function ProfilPValid(rec: PRecProfilP): boolean;
|
||
114 | procedure StringsProfilP(Liste: TStrings; IncludeInvalid: Boolean);
|
||
115 | // Simulation porc
|
||
116 | procedure InitSimulP;
|
||
117 | procedure FreeSimulP;
|
||
118 | procedure LoadSimulP;
|
||
119 | procedure SaveSimulP;
|
||
120 | function SimulPValid(rec: PRecSimulP): boolean;
|
||
121 | procedure StringsSimulP(Liste: TStrings; IncludeInvalid: Boolean);
|
||
122 | |||
123 | implementation
|
||
124 | |||
125 | uses
|
||
126 | SHFolder, Registry, IniFiles, UFindRec, UUtil, UStrings, UCalcul, UFMenu{, UFInraAfz};
|
||
127 | |||
128 | // Licence
|
||
129 | |||
130 | procedure InitLicense;
|
||
131 | var
|
||
132 | Buffer: Pointer; |
||
133 | Version: PVSFixedFileInfo; |
||
134 | BufferSize, VersionSize: DWORD; |
||
135 | VolumeSerialNumber, MaximumComponentLength, FileSystemFlags: DWORD; |
||
136 | NormalLicFileName, VirtualStoreLicFileName, FileDrive, VirtualStore: string;
|
||
137 | LocalAppData: array[0..MAX_PATH] of Char; |
||
138 | begin
|
||
139 | // Version du programme
|
||
140 | MajorVersion := 0;
|
||
141 | MinorVersion := 0;
|
||
142 | ReleaseVersion := 0;
|
||
143 | BuildVersion := 0;
|
||
144 | BufferSize := GetFileVersionInfoSize(PChar(Application.ExeName), BufferSize); |
||
145 | if BufferSize > 0 |
||
146 | then
|
||
147 | begin
|
||
148 | GetMem(Buffer, BufferSize); |
||
149 | if GetFileVersionInfo(PChar(Application.ExeName), 0, BufferSize, Buffer) |
||
150 | then
|
||
151 | begin
|
||
152 | VerQueryValue(Buffer, '\', Pointer(Version), VersionSize);
|
||
153 | MajorVersion := Version.dwFileVersionMS shr 16; |
||
154 | MinorVersion := Version.dwFileVersionMS and $FFFF; |
||
155 | ReleaseVersion := Version.dwFileVersionLS shr 16; |
||
156 | BuildVersion := Version.dwFileVersionLS and $FFFF; |
||
157 | end;
|
||
158 | FreeMem(Buffer, BufferSize); |
||
159 | end ;
|
||
160 | VersionString := Format('%d.%d.%d.%d', [MajorVersion, MinorVersion, ReleaseVersion, BuildVersion]);
|
||
161 | // Num?ro de s?rie du volume
|
||
162 | Drive := IncludeTrailingPathDelimiter(ExtractFileDrive(Application.ExeName)); |
||
163 | GetVolumeInformation(PChar(Drive), nil, 0, @VolumeSerialNumber, MaximumComponentLength, FileSystemFlags, nil, 0); |
||
164 | Volume := IntToHex(HiWord(VolumeSerialNumber), 4) + '-' + IntToHex(LoWord(VolumeSerialNumber), 4); |
||
165 | // Passage du fichier LIC ? la base de registre
|
||
166 | if not Reg.OpenKeyReadOnly('\Software\InraPorc\License') |
||
167 | then
|
||
168 | begin
|
||
169 | NormalLicFileName := ChangeFileExt(Application.ExeName, '.lic');
|
||
170 | if FileExists(NormalLicFileName)
|
||
171 | then // Importer les informations |
||
172 | LoadLicFile(NormalLicFileName); |
||
173 | // Prise en compte du VirtualStore (Windows Vista et Windows 7)
|
||
174 | FileDrive := ExtractFileDrive(NormalLicFileName); |
||
175 | SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, SHGFP_TYPE_CURRENT, LocalAppData); |
||
176 | VirtualStore := IncludeTrailingPathDelimiter(LocalAppData) + 'VirtualStore';
|
||
177 | VirtualStoreLicFileName := StringReplace(NormalLicFileName, FileDrive, VirtualStore, []); |
||
178 | if FileExists(VirtualStoreLicFileName)
|
||
179 | then // Importer les informations |
||
180 | LoadLicFile(VirtualStoreLicFileName); |
||
181 | if FileExists(NormalLicFileName) or FileExists(VirtualStoreLicFileName) |
||
182 | then // Enregistrer les informations import?es |
||
183 | SaveLicense; |
||
184 | end;
|
||
185 | end ;
|
||
186 | |||
187 | procedure LoadLicense;
|
||
188 | begin
|
||
189 | LicenseType := BdRReadInteger('\Software\InraPorc\License', 'LicenseType', 0); |
||
190 | LicenseNumber := BdRReadInteger('\Software\InraPorc\License', 'LicenseNumber', 0); |
||
191 | FirstName := BdRReadString('\Software\InraPorc\License', 'FirstName', ''); |
||
192 | LastName := BdRReadString('\Software\InraPorc\License', 'LastName', ''); |
||
193 | Company := BdRReadString('\Software\InraPorc\License', 'Company', ''); |
||
194 | Address1 := BdRReadString('\Software\InraPorc\License', 'Address1', ''); |
||
195 | Address2 := BdRReadString('\Software\InraPorc\License', 'Address2', ''); |
||
196 | PostalCode := BdRReadString('\Software\InraPorc\License', 'PostalCode', ''); |
||
197 | City := BdRReadString('\Software\InraPorc\License', 'City', ''); |
||
198 | Country := BdRReadString('\Software\InraPorc\License', 'Country', ''); |
||
199 | Phone := BdRReadString('\Software\InraPorc\License', 'Phone', ''); |
||
200 | Fax := BdRReadString('\Software\InraPorc\License', 'Fax', ''); |
||
201 | Mail := BdRReadString('\Software\InraPorc\License', 'Mail', ''); |
||
202 | Course := BdRReadString('\Software\InraPorc\License', 'Course', ''); |
||
203 | FinalDate := BdRReadString('\Software\InraPorc\License', 'FinalDate', '31/12/2099'); |
||
204 | SoftwareEnableKey := BdRReadString('\Software\InraPorc\License', 'SoftwareEnableKey', ''); |
||
205 | end;
|
||
206 | |||
207 | procedure SaveLicense;
|
||
208 | begin
|
||
209 | BdRWriteInteger('\Software\InraPorc\License', 'LicenseType', LicenseType); |
||
210 | BdRWriteInteger('\Software\InraPorc\License', 'LicenseNumber', LicenseNumber); |
||
211 | BdRWriteString('\Software\InraPorc\License', 'Version', VersionString); |
||
212 | BdRWriteString('\Software\InraPorc\License', 'FirstName', FirstName); |
||
213 | BdRWriteString('\Software\InraPorc\License', 'LastName', LastName); |
||
214 | BdRWriteString('\Software\InraPorc\License', 'Company', Company); |
||
215 | BdRWriteString('\Software\InraPorc\License', 'Address1', Address1); |
||
216 | BdRWriteString('\Software\InraPorc\License', 'Address2', Address2); |
||
217 | BdRWriteString('\Software\InraPorc\License', 'PostalCode', PostalCode); |
||
218 | BdRWriteString('\Software\InraPorc\License', 'City', City); |
||
219 | BdRWriteString('\Software\InraPorc\License', 'Country', Country); |
||
220 | BdRWriteString('\Software\InraPorc\License', 'Phone', Phone); |
||
221 | BdRWriteString('\Software\InraPorc\License', 'Fax', Fax); |
||
222 | BdRWriteString('\Software\InraPorc\License', 'Mail', Mail); |
||
223 | BdRWriteString('\Software\InraPorc\License', 'Course', Course); |
||
224 | BdRWriteString('\Software\InraPorc\License', 'VolumeSerialNumber', Volume); |
||
225 | BdRWriteString('\Software\InraPorc\License', 'FinalDate', FinalDate); |
||
226 | BdRWriteString('\Software\InraPorc\License', 'SoftwareEnableKey', SoftwareEnableKey); |
||
227 | end;
|
||
228 | |||
229 | procedure LoadLicFile(FileName: string); |
||
230 | begin
|
||
231 | Lic := TIniFile.Create(FileName); |
||
232 | LicenseType := Lic.ReadInteger('License', 'LicenseType', 0); |
||
233 | LicenseNumber := Lic.ReadInteger('License', 'LicenseNumber', 0); |
||
234 | FirstName := Lic.ReadString('License', 'FirstName', ''); |
||
235 | LastName := Lic.ReadString('License', 'LastName', ''); |
||
236 | Company := Lic.ReadString('License', 'Company', ''); |
||
237 | Address1 := Lic.ReadString('License', 'Address1', ''); |
||
238 | Address2 := Lic.ReadString('License', 'Address2', ''); |
||
239 | PostalCode := Lic.ReadString('License', 'PostalCode', ''); |
||
240 | City := Lic.ReadString('License', 'City', ''); |
||
241 | Country := Lic.ReadString('License', 'Country', ''); |
||
242 | Phone := Lic.ReadString('License', 'Phone', ''); |
||
243 | Fax := Lic.ReadString('License', 'Fax', ''); |
||
244 | Mail := Lic.ReadString('License', 'Mail', ''); |
||
245 | Course := Lic.ReadString('License', 'Course', ''); |
||
246 | FinalDate := Lic.ReadString('License', 'FinalDate', '31/12/2099'); |
||
247 | SoftwareEnableKey := Lic.ReadString('License', 'SoftwareEnableKey', ''); |
||
248 | Lic.Free; |
||
249 | end;
|
||
250 | |||
251 | procedure SaveLicFile(FileName: string); |
||
252 | begin
|
||
253 | Lic := TIniFile.Create(FileName); |
||
254 | Lic.WriteInteger('License', 'LicenseType', LicenseType); |
||
255 | Lic.WriteInteger('License', 'LicenseNumber', LicenseNumber); |
||
256 | Lic.WriteString('License', 'Version', VersionString); |
||
257 | Lic.WriteString('License', 'FirstName', FirstName); |
||
258 | Lic.WriteString('License', 'LastName', LastName); |
||
259 | Lic.WriteString('License', 'Company', Company); |
||
260 | Lic.WriteString('License', 'Address1', Address1); |
||
261 | Lic.WriteString('License', 'Address2', Address2); |
||
262 | Lic.WriteString('License', 'PostalCode', PostalCode); |
||
263 | Lic.WriteString('License', 'City', City); |
||
264 | Lic.WriteString('License', 'Country', Country); |
||
265 | Lic.WriteString('License', 'Phone', Phone); |
||
266 | Lic.WriteString('License', 'Fax', Fax); |
||
267 | Lic.WriteString('License', 'Mail', Mail); |
||
268 | Lic.WriteString('License', 'Course', Course); |
||
269 | Lic.WriteString('License', 'VolumeSerialNumber', Volume); |
||
270 | Lic.WriteString('License', 'FinalDate', FinalDate); |
||
271 | Lic.WriteString('License', 'SoftwareEnableKey', SoftwareEnableKey); |
||
272 | Lic.Free; |
||
273 | end;
|
||
274 | |||
275 | // Configuration
|
||
276 | |||
277 | procedure LoadConfig;
|
||
278 | var
|
||
279 | // Personal: string;
|
||
280 | Personal: array[0..MAX_PATH] of Char; |
||
281 | begin
|
||
282 | if Reg.OpenKeyReadOnly('\Software\InraPorc\Config\Network') |
||
283 | and Reg.ValueExists('CheckForUpdates') |
||
284 | then
|
||
285 | CheckForUpdates := BdRReadBoolean('\Software\InraPorc\Config\Network', 'CheckForUpdates', True) |
||
286 | else
|
||
287 | begin
|
||
288 | CheckForUpdates := MessageDlg(MsgCheckForUpdates, mtConfirmation, [mbYes, mbNo], 0) = mrYes;
|
||
289 | Reg.CloseKey; |
||
290 | BdRWriteBoolean('\Software\InraPorc\Config\Network', 'CheckForUpdates', CheckForUpdates); |
||
291 | end;
|
||
292 | // Personal := BdRReadString('\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', 'Personal', GetCurrentDir);
|
||
293 | SHGetFolderPath(0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, Personal); |
||
294 | Folder := BdRReadString('\Software\InraPorc\Config\Data', 'Folder', IncludeTrailingPathDelimiter(Personal) + 'InraPorc'); |
||
295 | ExcelFile := BdRReadString('\Software\InraPorc\Config\Data', 'ExcelFile', IncludeTrailingPathDelimiter(Folder) + 'InraPorc.xls'); |
||
296 | MainLeft := BdRReadInteger('\Software\InraPorc\Config\Window', 'MainLeft', 0); |
||
297 | MainTop := BdRReadInteger('\Software\InraPorc\Config\Window', 'MainTop', 0); |
||
298 | MainWidth := BdRReadInteger('\Software\InraPorc\Config\Window', 'MainWidth', 1024); |
||
299 | MainHeight := BdRReadInteger('\Software\InraPorc\Config\Window', 'MainHeight', 768); |
||
300 | Logo := BdRReadString('\Software\InraPorc\Config\Window', 'Logo', ''); |
||
301 | CurrencySign := BdRReadString('\Software\InraPorc\Config\International', 'CurrencySign', DefaultCurrency); |
||
302 | AffCorrCUD := BdRReadBoolean('\Software\InraPorc\Config\Messages', 'CorrCUD', True); |
||
303 | AffCalcAli := BdRReadBoolean('\Software\InraPorc\Config\Messages', 'CalcAli', True); |
||
304 | AffGraphAli := BdRReadBoolean('\Software\InraPorc\Config\Messages', 'GraphAli', True); |
||
305 | AffUnitProfilP := BdRReadBoolean('\Software\InraPorc\Config\Messages', 'UnitProfilP', True); |
||
306 | AffPDMoy := BdRReadBoolean('\Software\InraPorc\Config\Messages', 'PDMoy', True); |
||
307 | AffPrecocite := BdRReadBoolean('\Software\InraPorc\Config\Messages', 'Precocite', True); |
||
308 | AffEntretien := BdRReadBoolean('\Software\InraPorc\Config\Messages', 'Entretien', True); |
||
309 | AffOptInit := BdRReadBoolean('\Software\InraPorc\Config\Messages', 'OptInit', True); |
||
310 | AffSimulT := BdRReadBoolean('\Software\InraPorc\Config\Messages', 'SimulT', True); |
||
311 | AffBesoin := BdRReadBoolean('\Software\InraPorc\Config\Messages', 'Besoin', True); |
||
312 | ConfRap := BdRReadInteger('\Software\InraPorc\Config\Configuration', 'Rap', 0); |
||
313 | ConfDig := BdRReadInteger('\Software\InraPorc\Config\Configuration', 'Dig', 0); |
||
314 | ConfTCompo := BdRReadInteger('\Software\InraPorc\Config\Configuration', 'TCompo', 0); |
||
315 | ConfTAA := BdRReadInteger('\Software\InraPorc\Config\Configuration', 'TAA', 0); |
||
316 | ConfTAG := BdRReadInteger('\Software\InraPorc\Config\Configuration', 'TAG', 0); |
||
317 | ConfTMacro := BdRReadInteger('\Software\InraPorc\Config\Configuration', 'TMacro', 0); |
||
318 | ConfTOligo := BdRReadInteger('\Software\InraPorc\Config\Configuration', 'TOligo', 0); |
||
319 | ConfTFibres := BdRReadInteger('\Software\InraPorc\Config\Configuration', 'TFibres', 0); |
||
320 | ConfDCompo := BdRReadInteger('\Software\InraPorc\Config\Configuration', 'DCompo', 1); |
||
321 | ConfDAA := BdRReadInteger('\Software\InraPorc\Config\Configuration', 'DAA', 1); |
||
322 | ConfAffMP := BdRReadBoolean('\Software\InraPorc\Config\Configuration', 'AffMP', True); |
||
323 | TypeAliGest := BdRReadInteger('\Software\InraPorc\Config\AliGest', 'TypeAliGest', 2); |
||
324 | Duree1 := BdRReadInteger('\Software\InraPorc\Config\AliGest', 'Duree1', 28); |
||
325 | Duree3 := BdRReadInteger('\Software\InraPorc\Config\AliGest', 'Duree3', 21); |
||
326 | Quantite1 := BdRReadFloat('\Software\InraPorc\Config\AliGest', 'Quantite1', 3.0); |
||
327 | Quantite2 := BdRReadFloat('\Software\InraPorc\Config\AliGest', 'Quantite2', 2.5); |
||
328 | Quantite3 := BdRReadFloat('\Software\InraPorc\Config\AliGest', 'Quantite3', 3.0); |
||
329 | Augment := BdRReadFloat('\Software\InraPorc\Config\AliGest', 'Augment', 0.5); |
||
330 | XTruie := BdRReadInteger('\Software\InraPorc\Config\Graph', 'XTruie', 0); |
||
331 | XCrois := BdRReadInteger('\Software\InraPorc\Config\Graph', 'XCrois', 0); |
||
332 | CarTete := BdRReadBoolean('\Software\InraPorc\Config\Carcasse', 'Tete', True); |
||
333 | CarLangue := BdRReadBoolean('\Software\InraPorc\Config\Carcasse', 'Langue', True); |
||
334 | CarPieds := BdRReadBoolean('\Software\InraPorc\Config\Carcasse', 'Pieds', True); |
||
335 | CarQueue := BdRReadBoolean('\Software\InraPorc\Config\Carcasse', 'Queue', True); |
||
336 | CarHampe := BdRReadBoolean('\Software\InraPorc\Config\Carcasse', 'Hampe', False); |
||
337 | CarPanne := BdRReadBoolean('\Software\InraPorc\Config\Carcasse', 'Panne', False); |
||
338 | FeedInfo := BdRReadInteger('\Software\InraPorc\Config\InfoCrois', 'FeedInfo', 0); |
||
339 | FatInfo := BdRReadInteger('\Software\InraPorc\Config\InfoCrois', 'FatInfo', 0); |
||
340 | UserFatShortName := BdRReadString('\Software\InraPorc\Config\InfoCrois', 'UserFatShortName', ''); |
||
341 | UserFatLongName := BdRReadString('\Software\InraPorc\Config\InfoCrois', 'UserFatLongName', ''); |
||
342 | UserFatPVV := BdRReadBoolean('\Software\InraPorc\Config\InfoCrois', 'UserFatPVV', False); |
||
343 | UserFatA := BdRReadFloat('\Software\InraPorc\Config\InfoCrois', 'UserFatA', 0); |
||
344 | UserFatB := BdRReadFloat('\Software\InraPorc\Config\InfoCrois', 'UserFatB', 0); |
||
345 | UserFatC := BdRReadFloat('\Software\InraPorc\Config\InfoCrois', 'UserFatC', 0); |
||
346 | LeanInfo := BdRReadInteger('\Software\InraPorc\Config\InfoCrois', 'LeanInfo', 0); |
||
347 | UserLeanShortName := BdRReadString('\Software\InraPorc\Config\InfoCrois', 'UserLeanShortName', ''); |
||
348 | UserLeanLongName := BdRReadString('\Software\InraPorc\Config\InfoCrois', 'UserLeanLongName', ''); |
||
349 | UserLeanPVV := BdRReadBoolean('\Software\InraPorc\Config\InfoCrois', 'UserLeanPVV', False); |
||
350 | UserLeanA := BdRReadFloat('\Software\InraPorc\Config\InfoCrois', 'UserLeanA', 0); |
||
351 | UserLeanB := BdRReadFloat('\Software\InraPorc\Config\InfoCrois', 'UserLeanB', 0); |
||
352 | UserLeanC := BdRReadFloat('\Software\InraPorc\Config\InfoCrois', 'UserLeanC', 0); |
||
353 | ConfigChanged := False; |
||
354 | end;
|
||
355 | |||
356 | procedure SaveConfig;
|
||
357 | begin
|
||
358 | BdRWriteBoolean('\Software\InraPorc\Config\Network', 'CheckForUpdates', CheckForUpdates); |
||
359 | BdRWriteString('\Software\InraPorc\Config\Data', 'Folder', Folder); |
||
360 | BdRWriteString('\Software\InraPorc\Config\Data', 'ExcelFile', ExcelFile); |
||
361 | BdRWriteInteger('\Software\InraPorc\Config\Window', 'MainLeft', MainLeft); |
||
362 | BdRWriteInteger('\Software\InraPorc\Config\Window', 'MainTop', MainTop); |
||
363 | BdRWriteInteger('\Software\InraPorc\Config\Window', 'MainWidth', MainWidth); |
||
364 | BdRWriteInteger('\Software\InraPorc\Config\Window', 'MainHeight', MainHeight); |
||
365 | BdRWriteString('\Software\InraPorc\Config\Window', 'Logo', Logo); |
||
366 | BdRWriteString('\Software\InraPorc\Config\International', 'LanguageCode', LanguageCode); |
||
367 | BdRWriteString('\Software\InraPorc\Config\International', 'CurrencySign', CurrencySign); |
||
368 | BdRWriteInteger('\Software\InraPorc\Config\Configuration', 'Rap', ConfRap); |
||
369 | BdRWriteInteger('\Software\InraPorc\Config\Configuration', 'Dig', ConfDig); |
||
370 | BdRWriteInteger('\Software\InraPorc\Config\Configuration', 'TCompo', ConfTCompo); |
||
371 | BdRWriteInteger('\Software\InraPorc\Config\Configuration', 'TAA', ConfTAA); |
||
372 | BdRWriteInteger('\Software\InraPorc\Config\Configuration', 'TAG', ConfTAG); |
||
373 | BdRWriteInteger('\Software\InraPorc\Config\Configuration', 'TMacro', ConfTMacro); |
||
374 | BdRWriteInteger('\Software\InraPorc\Config\Configuration', 'TOligo', ConfTOligo); |
||
375 | BdRWriteInteger('\Software\InraPorc\Config\Configuration', 'TFibres', ConfTFibres); |
||
376 | BdRWriteInteger('\Software\InraPorc\Config\Configuration', 'DCompo', ConfDCompo); |
||
377 | BdRWriteInteger('\Software\InraPorc\Config\Configuration', 'DAA', ConfDAA); |
||
378 | BdRWriteBoolean('\Software\InraPorc\Config\Configuration', 'AffMP', ConfAffMP); |
||
379 | BdRWriteInteger('\Software\InraPorc\Config\AliGest', 'TypeAliGest', TypeAliGest); |
||
380 | BdRWriteInteger('\Software\InraPorc\Config\AliGest', 'Duree1', Duree1); |
||
381 | BdRWriteInteger('\Software\InraPorc\Config\AliGest', 'Duree3', Duree3); |
||
382 | BdRWriteFloat('\Software\InraPorc\Config\AliGest', 'Quantite1', Quantite1); |
||
383 | BdRWriteFloat('\Software\InraPorc\Config\AliGest', 'Quantite2', Quantite2); |
||
384 | BdRWriteFloat('\Software\InraPorc\Config\AliGest', 'Quantite3', Quantite3); |
||
385 | BdRWriteFloat('\Software\InraPorc\Config\AliGest', 'Augment', Augment); |
||
386 | BdRWriteInteger('\Software\InraPorc\Config\Graph', 'XTruie', XTruie); |
||
387 | BdRWriteInteger('\Software\InraPorc\Config\Graph', 'XCrois', XCrois); |
||
388 | BdRWriteBoolean('\Software\InraPorc\Config\Carcasse', 'Tete', CarTete); |
||
389 | BdRWriteBoolean('\Software\InraPorc\Config\Carcasse', 'Langue', CarLangue); |
||
390 | BdRWriteBoolean('\Software\InraPorc\Config\Carcasse', 'Pieds', CarPieds); |
||
391 | BdRWriteBoolean('\Software\InraPorc\Config\Carcasse', 'Queue', CarQueue); |
||
392 | BdRWriteBoolean('\Software\InraPorc\Config\Carcasse', 'Hampe', CarHampe); |
||
393 | BdRWriteBoolean('\Software\InraPorc\Config\Carcasse', 'Panne', CarPanne); |
||
394 | BdRWriteInteger('\Software\InraPorc\Config\InfoCrois', 'FeedInfo', FeedInfo); |
||
395 | BdRWriteInteger('\Software\InraPorc\Config\InfoCrois', 'FatInfo', FatInfo); |
||
396 | BdRWriteString('\Software\InraPorc\Config\InfoCrois', 'UserFatShortName', UserFatShortName); |
||
397 | BdRWriteString('\Software\InraPorc\Config\InfoCrois', 'UserFatLongName', UserFatLongName); |
||
398 | BdRWriteBoolean('\Software\InraPorc\Config\InfoCrois', 'UserFatPVV', UserFatPVV); |
||
399 | BdRWriteFloat('\Software\InraPorc\Config\InfoCrois', 'UserFatA', UserFatA); |
||
400 | BdRWriteFloat('\Software\InraPorc\Config\InfoCrois', 'UserFatB', UserFatB); |
||
401 | BdRWriteFloat('\Software\InraPorc\Config\InfoCrois', 'UserFatC', UserFatC); |
||
402 | BdRWriteInteger('\Software\InraPorc\Config\InfoCrois', 'LeanInfo', LeanInfo); |
||
403 | BdRWriteString('\Software\InraPorc\Config\InfoCrois', 'UserLeanShortName', UserLeanShortName); |
||
404 | BdRWriteString('\Software\InraPorc\Config\InfoCrois', 'UserLeanLongName', UserLeanLongName); |
||
405 | BdRWriteBoolean('\Software\InraPorc\Config\InfoCrois', 'UserLeanPVV', UserLeanPVV); |
||
406 | BdRWriteFloat('\Software\InraPorc\Config\InfoCrois', 'UserLeanA', UserLeanA); |
||
407 | BdRWriteFloat('\Software\InraPorc\Config\InfoCrois', 'UserLeanB', UserLeanB); |
||
408 | BdRWriteFloat('\Software\InraPorc\Config\InfoCrois', 'UserLeanC', UserLeanC); |
||
409 | ConfigChanged := False; |
||
410 | end;
|
||
411 | |||
412 | // Donn?es
|
||
413 | |||
414 | procedure InitData;
|
||
415 | begin
|
||
416 | InitMatiere; |
||
417 | InitAliment; |
||
418 | InitSeqAliT; |
||
419 | InitRationT; |
||
420 | InitLogeT; |
||
421 | InitProfilT; |
||
422 | InitSimulT; |
||
423 | InitSeqAliP; |
||
424 | InitRationP; |
||
425 | InitProfilP; |
||
426 | InitSimulP; |
||
427 | end;
|
||
428 | |||
429 | procedure FreeData;
|
||
430 | begin
|
||
431 | FreeMatiere; |
||
432 | FreeAliment; |
||
433 | FreeSeqAliT; |
||
434 | FreeRationT; |
||
435 | FreeLogeT; |
||
436 | FreeProfilT; |
||
437 | FreeSimulT; |
||
438 | FreeSeqAliP; |
||
439 | FreeRationP; |
||
440 | FreeProfilP; |
||
441 | FreeSimulP; |
||
442 | end;
|
||
443 | |||
444 | procedure LoadData;
|
||
445 | begin
|
||
446 | if (not FileExists(NFicRationP) and FileExists(NFicRationPold)) |
||
447 | or (not FileExists(NFicProfilP) and FileExists(NFicProfilPold)) |
||
448 | then // Conversion n?cessaire |
||
449 | if IsComplete or IsEducation |
||
450 | then // Proposer la conversion |
||
451 | ConvertData := MessageDlg(MsgConvert, mtConfirmation, [mbYes, mbNo], 0) = mrYes
|
||
452 | else // Conversion automatique (pas d'enregistrement) |
||
453 | ConvertData := True |
||
454 | else // Pas de conversion |
||
455 | ConvertData := False; |
||
456 | LoadMatiere; |
||
457 | LoadAliment; |
||
458 | LoadSeqAliT; |
||
459 | LoadRationT; |
||
460 | LoadLogeT; |
||
461 | LoadProfilT; |
||
462 | LoadSimulT; |
||
463 | LoadSeqAliP; |
||
464 | LoadRationP; |
||
465 | LoadProfilP; |
||
466 | LoadSimulP; |
||
467 | end;
|
||
468 | |||
469 | procedure SaveData;
|
||
470 | begin
|
||
471 | SaveMatiere; |
||
472 | SaveAliment; |
||
473 | SaveSeqAliT; |
||
474 | SaveRationT; |
||
475 | SaveLogeT; |
||
476 | SaveProfilT; |
||
477 | SaveSimulT; |
||
478 | SaveSeqAliP; |
||
479 | SaveRationP; |
||
480 | SaveProfilP; |
||
481 | SaveSimulP; |
||
482 | end;
|
||
483 | |||
484 | // Mati?re premi?re
|
||
485 | |||
486 | procedure InitMatiere ;
|
||
487 | begin
|
||
488 | ListMatiere := TList.Create ; |
||
489 | NFicMatiere := 'Matiere.rec' ;
|
||
490 | NFicMatInraAfz := ExtractFilePath (Application.ExeName) + 'InraAfz.rec' ;
|
||
491 | end ;
|
||
492 | |||
493 | procedure FreeMatiere ;
|
||
494 | var
|
||
495 | i : integer ; |
||
496 | rec : PRecMatiere ; |
||
497 | begin
|
||
498 | if ListMatiere.Count > 0 |
||
499 | then
|
||
500 | for i := 0 to ListMatiere.Count - 1 do |
||
501 | begin
|
||
502 | rec := ListMatiere[i] ; |
||
503 | Dispose (rec) ; |
||
504 | end ;
|
||
505 | ListMatiere.Free ; |
||
506 | end ;
|
||
507 | |||
508 | procedure LoadMatiere ;
|
||
509 | var
|
||
510 | i : integer ; |
||
511 | fic : file of RecMatiere ; |
||
512 | rec : PRecMatiere ; |
||
513 | begin
|
||
514 | // effacement de la liste avant chargement
|
||
515 | if ListMatiere.Count > 0 |
||
516 | then
|
||
517 | for i := 0 to ListMatiere.Count - 1 do |
||
518 | begin
|
||
519 | rec := ListMatiere[i] ; |
||
520 | Dispose (rec) ; |
||
521 | end ;
|
||
522 | ListMatiere.Clear ; |
||
523 | // chargement des mati?res premi?res INRA-AFZ
|
||
524 | NumMatInraAfz := 0 ;
|
||
525 | if FileExists (NFicMatInraAfz)
|
||
526 | then
|
||
527 | begin
|
||
528 | FileMode := fmOpenRead; |
||
529 | AssignFile (fic, NFicMatInraAfz) ; |
||
530 | Reset (fic) ; |
||
531 | while not Eof (fic) do |
||
532 | begin
|
||
533 | New (rec) ; |
||
534 | Read (fic, rec^) ;
|
||
535 | // Traduction
|
||
536 | // rec.Nom := FInraAfz.LBNom.Items[NumMatInraAfz] ;
|
||
537 | // rec.Memo := FInraAfz.LBMemo.Items[NumMatInraAfz] ;
|
||
538 | ListMatiere.Add (rec) ; |
||
539 | Inc (NumMatInraAfz) ; |
||
540 | end ;
|
||
541 | CloseFile (fic) ; |
||
542 | FileMode := fmOpenReadWrite; |
||
543 | end ;
|
||
544 | // chargement du fichier
|
||
545 | if FileExists (NFicMatiere)
|
||
546 | then
|
||
547 | begin
|
||
548 | AssignFile (fic, NFicMatiere) ; |
||
549 | Reset (fic) ; |
||
550 | while not Eof (fic) do |
||
551 | begin
|
||
552 | New (rec) ; |
||
553 | Read (fic, rec^) ;
|
||
554 | ListMatiere.Add (rec) ; |
||
555 | end ;
|
||
556 | CloseFile (fic) ; |
||
557 | end ;
|
||
558 | end ;
|
||
559 | |||
560 | procedure SaveMatiere ;
|
||
561 | var
|
||
562 | i : integer ; |
||
563 | fic : file of RecMatiere ; |
||
564 | rec : PRecMatiere ; |
||
565 | begin
|
||
566 | if not IsComplete and not IsEducation |
||
567 | then
|
||
568 | Exit ; |
||
569 | AssignFile (fic, NFicMatiere) ; |
||
570 | Rewrite (fic) ; |
||
571 | if ListMatiere.Count > NumMatInraAfz
|
||
572 | then
|
||
573 | for i := NumMatInraAfz to ListMatiere.Count - 1 do |
||
574 | begin
|
||
575 | rec := ListMatiere[i] ; |
||
576 | Write (fic, rec^) ;
|
||
577 | end ;
|
||
578 | CloseFile (fic) ; |
||
579 | end ;
|
||
580 | |||
581 | function MatiereUsed (Numero : integer) : boolean ;
|
||
582 | var
|
||
583 | i, j : integer ; |
||
584 | ok : boolean ; |
||
585 | recAliment : PRecAliment ; |
||
586 | begin
|
||
587 | ok := FALSE ; |
||
588 | // Utilisation d'une mati?re premi?re dans un aliment
|
||
589 | if ListAliment.Count > 0 |
||
590 | then
|
||
591 | for i := 0 to ListAliment.Count - 1 do |
||
592 | begin
|
||
593 | recAliment := ListAliment[i] ; |
||
594 | if recAliment.MP.NbMat > 0 |
||
595 | then
|
||
596 | for j := 0 to recAliment.MP.NbMat - 1 do |
||
597 | if recAliment.MP.NumMat[j] = Numero
|
||
598 | then
|
||
599 | ok := TRUE ; |
||
600 | end ;
|
||
601 | result := ok ; |
||
602 | end ;
|
||
603 | |||
604 | function MatiereFound (Numero : integer) : boolean ;
|
||
605 | var
|
||
606 | i : integer ; |
||
607 | ok : boolean ; |
||
608 | recMatiere : PRecMatiere ; |
||
609 | begin
|
||
610 | ok := FALSE ; |
||
611 | i := 0 ;
|
||
612 | while (i < ListMatiere.Count) and not ok do |
||
613 | begin
|
||
614 | recMatiere := ListMatiere[i] ; |
||
615 | if recMatiere.Num = Numero
|
||
616 | then
|
||
617 | ok := TRUE |
||
618 | else
|
||
619 | Inc (i) ; |
||
620 | end ;
|
||
621 | result := ok ; |
||
622 | end ;
|
||
623 | |||
624 | function MatiereValid (rec : PRecMatiere) : boolean ;
|
||
625 | var
|
||
626 | ok : boolean ; |
||
627 | begin
|
||
628 | ok := TRUE ; |
||
629 | with rec^ do |
||
630 | if CC.MS = 0 then ok := FALSE ; |
||
631 | result := ok ; |
||
632 | end ;
|
||
633 | |||
634 | procedure StringsMatiere (Liste : TStrings ; TypeMatiere : Integer ;
|
||
635 | IncludeInvalid, IncludeInraAfz : Boolean) ; |
||
636 | var
|
||
637 | i : integer ; |
||
638 | rec : PRecMatiere ; |
||
639 | begin
|
||
640 | Liste.Clear ; |
||
641 | if ListMatiere.Count > 0 |
||
642 | then
|
||
643 | for i := 0 to ListMatiere.Count - 1 do |
||
644 | begin
|
||
645 | rec := ListMatiere[i] ; |
||
646 | if ((TypeMatiere = 0) or (rec.Typ = TypeMatiere)) |
||
647 | and (IncludeInvalid or MatiereValid (rec)) |
||
648 | and (IncludeInraAfz or (rec.Num > 0)) |
||
649 | // and (IsComplete or (rec.Num <= 10))
|
||
650 | then
|
||
651 | // Liste.Add (rec.Nom) ;
|
||
652 | if rec.Num > 0 |
||
653 | then // Mati?re premi?re utilisateur |
||
654 | Liste.Add(rec.Nom) |
||
655 | else // Mati?re premi?re INRA-AFZ (traduction) |
||
656 | Liste.Add(dgettext('InraAfz', rec.Nom));
|
||
657 | end ;
|
||
658 | end ;
|
||
659 | |||
660 | // Aliment
|
||
661 | |||
662 | procedure InitAliment ;
|
||
663 | begin
|
||
664 | ListAliment := TList.Create ; |
||
665 | NFicAliment := 'Aliment.rec' ;
|
||
666 | end ;
|
||
667 | |||
668 | procedure FreeAliment ;
|
||
669 | var
|
||
670 | i : integer ; |
||
671 | rec : PRecAliment ; |
||
672 | begin
|
||
673 | if ListAliment.Count > 0 |
||
674 | then
|
||
675 | for i := 0 to ListAliment.Count - 1 do |
||
676 | begin
|
||
677 | rec := ListAliment[i] ; |
||
678 | Dispose (rec) ; |
||
679 | end ;
|
||
680 | ListAliment.Free ; |
||
681 | end ;
|
||
682 | |||
683 | procedure LoadAliment ;
|
||
684 | var
|
||
685 | i : integer ; |
||
686 | fic : file of RecAliment ; |
||
687 | rec : PRecAliment ; |
||
688 | begin
|
||
689 | // effacement de la liste avant chargement
|
||
690 | if ListAliment.Count > 0 |
||
691 | then
|
||
692 | for i := 0 to ListAliment.Count - 1 do |
||
693 | begin
|
||
694 | rec := ListAliment[i] ; |
||
695 | Dispose (rec) ; |
||
696 | end ;
|
||
697 | ListAliment.Clear ; |
||
698 | // chargement du fichier
|
||
699 | if FileExists (NFicAliment)
|
||
700 | then
|
||
701 | begin
|
||
702 | AssignFile (fic, NFicAliment) ; |
||
703 | Reset (fic) ; |
||
704 | while not Eof (fic) do |
||
705 | begin
|
||
706 | New (rec) ; |
||
707 | Read (fic, rec^) ;
|
||
708 | ListAliment.Add (rec) ; |
||
709 | end ;
|
||
710 | CloseFile (fic) ; |
||
711 | end ;
|
||
712 | end ;
|
||
713 | |||
714 | procedure SaveAliment ;
|
||
715 | var
|
||
716 | i : integer ; |
||
717 | fic : file of RecAliment ; |
||
718 | rec : PRecAliment ; |
||
719 | begin
|
||
720 | if not IsComplete and not IsEducation |
||
721 | then
|
||
722 | Exit ; |
||
723 | AssignFile (fic, NFicAliment) ; |
||
724 | Rewrite (fic) ; |
||
725 | if ListAliment.Count > 0 |
||
726 | then
|
||
727 | for i := 0 to ListAliment.Count - 1 do |
||
728 | begin
|
||
729 | rec := ListAliment[i] ; |
||
730 | Write (fic, rec^) ;
|
||
731 | end ;
|
||
732 | CloseFile (fic) ; |
||
733 | end ;
|
||
734 | |||
735 | function AlimentUsed (Numero : integer) : boolean ;
|
||
736 | var
|
||
737 | i, j : integer ; |
||
738 | ok : boolean ; |
||
739 | recSeqAliT : PRecSeqAliT ; |
||
740 | recSeqAliP : PRecSeqAliP ; |
||
741 | begin
|
||
742 | ok := FALSE ; |
||
743 | // Utilisation de l'aliment dans une s?quence alimentaire truie
|
||
744 | if ListSeqAliT.Count > 0 |
||
745 | then
|
||
746 | for i := 0 to ListSeqAliT.Count - 1 do |
||
747 | begin
|
||
748 | recSeqAliT := ListSeqAliT[i] ; |
||
749 | for j := 1 to recSeqAliT.NbRuleGest do |
||
750 | if (recSeqAliT.RuleGest[j].NumAli1 = Numero)
|
||
751 | or (recSeqAliT.RuleGest[j].NumAli2 = Numero)
|
||
752 | then
|
||
753 | ok := TRUE ; |
||
754 | for j := 1 to recSeqAliT.NbRuleLact do |
||
755 | if (recSeqAliT.RuleLact[j].NumAli1 = Numero)
|
||
756 | or (recSeqAliT.RuleLact[j].NumAli2 = Numero)
|
||
757 | then
|
||
758 | ok := TRUE ; |
||
759 | for j := 1 to recSeqAliT.NbRuleISSF do |
||
760 | if (recSeqAliT.RuleISSF[j].NumAli1 = Numero)
|
||
761 | or (recSeqAliT.RuleISSF[j].NumAli2 = Numero)
|
||
762 | then
|
||
763 | ok := TRUE ; |
||
764 | end ;
|
||
765 | // Utilisation de l'aliment dans une s?quence alimentaire porc
|
||
766 | if ListSeqAliP.Count > 0 |
||
767 | then
|
||
768 | for i := 0 to ListSeqAliP.Count - 1 do |
||
769 | begin
|
||
770 | recSeqAliP := ListSeqAliP[i] ; |
||
771 | for j := 1 to recSeqAliP.NbRule do |
||
772 | if (recSeqAliP.Rule[j].NumAli1 = Numero)
|
||
773 | or (recSeqAliP.Rule[j].NumAli2 = Numero)
|
||
774 | then
|
||
775 | ok := TRUE ; |
||
776 | end ;
|
||
777 | result := ok ; |
||
778 | end ;
|
||
779 | |||
780 | function AlimentFound (Numero : integer) : boolean ;
|
||
781 | var
|
||
782 | i : integer ; |
||
783 | ok : boolean ; |
||
784 | recAliment : PRecAliment ; |
||
785 | begin
|
||
786 | ok := FALSE ; |
||
787 | i := 0 ;
|
||
788 | while (i < ListAliment.Count) and not ok do |
||
789 | begin
|
||
790 | recAliment := ListAliment[i] ; |
||
791 | if recAliment.Num = Numero
|
||
792 | then
|
||
793 | ok := TRUE |
||
794 | else
|
||
795 | Inc (i) ; |
||
796 | end ;
|
||
797 | result := ok ; |
||
798 | end ;
|
||
799 | |||
800 | function AlimentValid (rec : PRecAliment) : boolean ;
|
||
801 | var
|
||
802 | i : integer ; |
||
803 | ok : boolean ; |
||
804 | begin
|
||
805 | ok := TRUE ; |
||
806 | with rec^ do |
||
807 | begin
|
||
808 | if CC.MS = 0 then ok := FALSE ; |
||
809 | if MP.NbMat > 0 |
||
810 | then
|
||
811 | for i := 0 to MP.NbMat - 1 do |
||
812 | if MP.NumMat[i] = 0 then ok := FALSE ; |
||
813 | end ;
|
||
814 | result := ok ; |
||
815 | end ;
|
||
816 | |||
817 | procedure StringsAliment (Liste : TStrings ; TypeAliment : Integer ;
|
||
818 | IncludeInvalid : Boolean) ; |
||
819 | var
|
||
820 | i : integer ; |
||
821 | rec : PRecAliment ; |
||
822 | begin
|
||
823 | Liste.Clear ; |
||
824 | if ListAliment.Count > 0 |
||
825 | then
|
||
826 | for i := 0 to ListAliment.Count - 1 do |
||
827 | begin
|
||
828 | rec := ListAliment[i] ; |
||
829 | if ((TypeAliment = 0) or (rec.Typ = TypeAliment)) |
||
830 | and (IncludeInvalid or AlimentValid (rec)) |
||
831 | // and (IsComplete or (rec.Num <= 10))
|
||
832 | then
|
||
833 | Liste.Add (rec.Nom) ; |
||
834 | end ;
|
||
835 | end ;
|
||
836 | |||
837 | // S?quence alimentaire truie
|
||
838 | |||
839 | procedure InitSeqAliT ;
|
||
840 | begin
|
||
841 | ListSeqAliT := TList.Create ; |
||
842 | NFicSeqAliT := 'SeqAliT.rec' ;
|
||
843 | end ;
|
||
844 | |||
845 | procedure FreeSeqAliT ;
|
||
846 | var
|
||
847 | i : integer ; |
||
848 | rec : PRecSeqAliT ; |
||
849 | begin
|
||
850 | if ListSeqAliT.Count > 0 |
||
851 | then
|
||
852 | for i := 0 to ListSeqAliT.Count - 1 do |
||
853 | begin
|
||
854 | rec := ListSeqAliT[i] ; |
||
855 | Dispose (rec) ; |
||
856 | end ;
|
||
857 | ListSeqAliT.Free ; |
||
858 | end ;
|
||
859 | |||
860 | procedure LoadSeqAliT ;
|
||
861 | var
|
||
862 | i : integer ; |
||
863 | fic : file of RecSeqAliT ; |
||
864 | rec : PRecSeqAliT ; |
||
865 | begin
|
||
866 | // effacement de la liste avant chargement
|
||
867 | if ListSeqAliT.Count > 0 |
||
868 | then
|
||
869 | for i := 0 to ListSeqAliT.Count - 1 do |
||
870 | begin
|
||
871 | rec := ListSeqAliT[i] ; |
||
872 | Dispose (rec) ; |
||
873 | end ;
|
||
874 | ListSeqAliT.Clear ; |
||
875 | // chargement du fichier
|
||
876 | if FileExists (NFicSeqAliT)
|
||
877 | then
|
||
878 | begin
|
||
879 | AssignFile (fic, NFicSeqAliT) ; |
||
880 | Reset (fic) ; |
||
881 | while not Eof (fic) do |
||
882 | begin
|
||
883 | New (rec) ; |
||
884 | Read (fic, rec^) ;
|
||
885 | ListSeqAliT.Add (rec) ; |
||
886 | end ;
|
||
887 | CloseFile (fic) ; |
||
888 | end ;
|
||
889 | end ;
|
||
890 | |||
891 | procedure SaveSeqAliT ;
|
||
892 | var
|
||
893 | i : integer ; |
||
894 | fic : file of RecSeqAliT ; |
||
895 | rec : PRecSeqAliT ; |
||
896 | begin
|
||
897 | if not IsComplete and not IsEducation |
||
898 | then
|
||
899 | Exit ; |
||
900 | AssignFile (fic, NFicSeqAliT) ; |
||
901 | Rewrite (fic) ; |
||
902 | if ListSeqAliT.Count > 0 |
||
903 | then
|
||
904 | for i := 0 to ListSeqAliT.Count - 1 do |
||
905 | begin
|
||
906 | rec := ListSeqAliT[i] ; |
||
907 | Write (fic, rec^) ;
|
||
908 | end ;
|
||
909 | CloseFile (fic) ; |
||
910 | end ;
|
||
911 | |||
912 | function SeqAliTUsed (Numero : integer) : boolean ;
|
||
913 | var
|
||
914 | i, j : integer ; |
||
915 | ok : boolean ; |
||
916 | recProfilT : PRecProfilT ; |
||
917 | recSimulT : PRecSimulT ; |
||
918 | begin
|
||
919 | ok := FALSE ; |
||
920 | // Utilisation de la s?quence alimentaire dans un profil animal
|
||
921 | if ListProfilT.Count > 0 |
||
922 | then
|
||
923 | for i := 0 to ListProfilT.Count - 1 do |
||
924 | begin
|
||
925 | recProfilT := ListProfilT[i] ; |
||
926 | if recProfilT.SeqAli = Numero
|
||
927 | then
|
||
928 | ok := TRUE ; |
||
929 | end ;
|
||
930 | // Utilisation de la s?quence alimentaire dans une simulation
|
||
931 | if ListSimulT.Count > 0 |
||
932 | then
|
||
933 | for i := 0 to ListSimulT.Count - 1 do |
||
934 | begin
|
||
935 | recSimulT := ListSimulT[i] ; |
||
936 | for j := recSimulT.StadeInit div 3 to recSimulT.StadeFin div 3 do |
||
937 | if recSimulT.SeqAli[j] = Numero
|
||
938 | then
|
||
939 | ok := TRUE ; |
||
940 | end ;
|
||
941 | result := ok ; |
||
942 | end ;
|
||
943 | |||
944 | function SeqAliTFound (Numero : integer) : boolean ;
|
||
945 | var
|
||
946 | i : integer ; |
||
947 | ok : boolean ; |
||
948 | recSeqAliT : PRecSeqAliT ; |
||
949 | begin
|
||
950 | ok := FALSE ; |
||
951 | i := 0 ;
|
||
952 | while (i < ListSeqAliT.Count) and not ok do |
||
953 | begin
|
||
954 | recSeqAliT := ListSeqAliT[i] ; |
||
955 | if recSeqAliT.Num = Numero
|
||
956 | then
|
||
957 | ok := TRUE |
||
958 | else
|
||
959 | Inc (i) ; |
||
960 | end ;
|
||
961 | result := ok ; |
||
962 | end ;
|
||
963 | |||
964 | function SeqAliTValid (rec : PRecSeqAliT) : boolean ;
|
||
965 | var
|
||
966 | i : integer ; |
||
967 | ok : boolean ; |
||
968 | begin
|
||
969 | ok := TRUE ; |
||
970 | with rec^ do |
||
971 | begin
|
||
972 | for i := 1 to NbRuleGest do |
||
973 | if RuleGest[i].NumAli1 = -1 |
||
974 | then
|
||
975 | ok := FALSE |
||
976 | else
|
||
977 | begin
|
||
978 | PAliment := ListAliment[FindIdxAliment (FindNomAliment (RuleGest[i].NumAli1))] ; |
||
979 | if not AlimentValid (PAliment) then ok := FALSE ; |
||
980 | end ;
|
||
981 | for i := 1 to NbRuleLact do |
||
982 | if RuleLact[i].NumAli1 = -1 |
||
983 | then
|
||
984 | ok := FALSE |
||
985 | else
|
||
986 | begin
|
||
987 | PAliment := ListAliment[FindIdxAliment (FindNomAliment (RuleLact[i].NumAli1))] ; |
||
988 | if not AlimentValid (PAliment) then ok := FALSE ; |
||
989 | end ;
|
||
990 | for i := 1 to NbRuleISSF do |
||
991 | if RuleISSF[i].NumAli1 = -1 |
||
992 | then
|
||
993 | ok := FALSE |
||
994 | else
|
||
995 | begin
|
||
996 | PAliment := ListAliment[FindIdxAliment (FindNomAliment (RuleISSF[i].NumAli1))] ; |
||
997 | if not AlimentValid (PAliment) then ok := FALSE ; |
||
998 | end ;
|
||
999 | end ;
|
||
1000 | result := ok ; |
||
1001 | end ;
|
||
1002 | |||
1003 | procedure StringsSeqAliT (Liste : TStrings ; IncludeInvalid : Boolean) ;
|
||
1004 | var
|
||
1005 | i : integer ; |
||
1006 | rec : PRecSeqAliT ; |
||
1007 | begin
|
||
1008 | Liste.Clear ; |
||
1009 | if ListSeqAliT.Count > 0 |
||
1010 | then
|
||
1011 | for i := 0 to ListSeqAliT.Count - 1 do |
||
1012 | begin
|
||
1013 | rec := ListSeqAliT[i] ; |
||
1014 | if (IncludeInvalid or SeqAliTValid (rec)) |
||
1015 | // and (IsComplete or (rec.Num <= 5))
|
||
1016 | then
|
||
1017 | Liste.Add (rec.Nom) ; |
||
1018 | end ;
|
||
1019 | end ;
|
||
1020 | |||
1021 | // Plan de rationnement truie
|
||
1022 | |||
1023 | procedure InitRationT ;
|
||
1024 | begin
|
||
1025 | ListRationT := TList.Create ; |
||
1026 | NFicRationT := 'RationT.rec' ;
|
||
1027 | end ;
|
||
1028 | |||
1029 | procedure FreeRationT ;
|
||
1030 | var
|
||
1031 | i : integer ; |
||
1032 | rec : PRecRationT ; |
||
1033 | begin
|
||
1034 | if ListRationT.Count > 0 |
||
1035 | then
|
||
1036 | for i := 0 to ListRationT.Count - 1 do |
||
1037 | begin
|
||
1038 | rec := ListRationT[i] ; |
||
1039 | Dispose (rec) ; |
||
1040 | end ;
|
||
1041 | ListRationT.Free ; |
||
1042 | end ;
|
||
1043 | |||
1044 | procedure LoadRationT ;
|
||
1045 | var
|
||
1046 | i : integer ; |
||
1047 | fic : file of RecRationT ; |
||
1048 | rec : PRecRationT ; |
||
1049 | begin
|
||
1050 | // effacement de la liste avant chargement
|
||
1051 | if ListRationT.Count > 0 |
||
1052 | then
|
||
1053 | for i := 0 to ListRationT.Count - 1 do |
||
1054 | begin
|
||
1055 | rec := ListRationT[i] ; |
||
1056 | Dispose (rec) ; |
||
1057 | end ;
|
||
1058 | ListRationT.Clear ; |
||
1059 | // chargement du fichier
|
||
1060 | if FileExists (NFicRationT)
|
||
1061 | then
|
||
1062 | begin
|
||
1063 | AssignFile (fic, NFicRationT) ; |
||
1064 | Reset (fic) ; |
||
1065 | while not Eof (fic) do |
||
1066 | begin
|
||
1067 | New (rec) ; |
||
1068 | Read (fic, rec^) ;
|
||
1069 | ListRationT.Add (rec) ; |
||
1070 | end ;
|
||
1071 | CloseFile (fic) ; |
||
1072 | end ;
|
||
1073 | end ;
|
||
1074 | |||
1075 | procedure SaveRationT ;
|
||
1076 | var
|
||
1077 | i : integer ; |
||
1078 | fic : file of RecRationT ; |
||
1079 | rec : PRecRationT ; |
||
1080 | begin
|
||
1081 | if not IsComplete and not IsEducation |
||
1082 | then
|
||
1083 | Exit ; |
||
1084 | AssignFile (fic, NFicRationT) ; |
||
1085 | Rewrite (fic) ; |
||
1086 | if ListRationT.Count > 0 |
||
1087 | then
|
||
1088 | for i := 0 to ListRationT.Count - 1 do |
||
1089 | begin
|
||
1090 | rec := ListRationT[i] ; |
||
1091 | Write (fic, rec^) ;
|
||
1092 | end ;
|
||
1093 | CloseFile (fic) ; |
||
1094 | end ;
|
||
1095 | |||
1096 | function RationTUsed (Numero : integer) : boolean ;
|
||
1097 | var
|
||
1098 | i, j : integer ; |
||
1099 | ok : boolean ; |
||
1100 | recSimulT : PRecSimulT ; |
||
1101 | begin
|
||
1102 | ok := FALSE ; |
||
1103 | // Utilisation du plan de rationnement dans une simulation
|
||
1104 | if ListSimulT.Count > 0 |
||
1105 | then
|
||
1106 | for i := 0 to ListSimulT.Count - 1 do |
||
1107 | begin
|
||
1108 | recSimulT := ListSimulT[i] ; |
||
1109 | for j := recSimulT.StadeInit div 3 to recSimulT.StadeFin div 3 do |
||
1110 | if recSimulT.Ration[j] = Numero
|
||
1111 | then
|
||
1112 | ok := TRUE ; |
||
1113 | end ;
|
||
1114 | result := ok ; |
||
1115 | end ;
|
||
1116 | |||
1117 | function RationTFound (Numero : integer) : boolean ;
|
||
1118 | var
|
||
1119 | i : integer ; |
||
1120 | ok : boolean ; |
||
1121 | recRationT : PRecRationT ; |
||
1122 | begin
|
||
1123 | ok := FALSE ; |
||
1124 | i := 0 ;
|
||
1125 | while (i < ListRationT.Count) and not ok do |
||
1126 | begin
|
||
1127 | recRationT := ListRationT[i] ; |
||
1128 | if recRationT.Num = Numero
|
||
1129 | then
|
||
1130 | ok := TRUE |
||
1131 | else
|
||
1132 | Inc (i) ; |
||
1133 | end ;
|
||
1134 | result := ok ; |
||
1135 | end ;
|
||
1136 | |||
1137 | function RationTValid (rec : PRecRationT) : boolean ;
|
||
1138 | var
|
||
1139 | i : integer ; |
||
1140 | ok : boolean ; |
||
1141 | begin
|
||
1142 | ok := TRUE ; |
||
1143 | with rec^ do |
||
1144 | begin
|
||
1145 | for i := 1 to NbRuleGest do |
||
1146 | if RuleGest[i].a = 0 then ok := FALSE ; |
||
1147 | for i := 1 to NbRuleLact do |
||
1148 | case RuleLact[i].Equation of |
||
1149 | 1 : // Lin?aire |
||
1150 | begin
|
||
1151 | if RuleLact[i].a = 0 then ok := FALSE ; |
||
1152 | if RuleLact[i].b = 0 then ok := FALSE ; |
||
1153 | end ;
|
||
1154 | 2 : // Lin?aire-plateau |
||
1155 | begin
|
||
1156 | if RuleLact[i].a = 0 then ok := FALSE ; |
||
1157 | if RuleLact[i].b = 0 then ok := FALSE ; |
||
1158 | if RuleLact[i].c <= RuleLact[i].a then ok := FALSE ; |
||
1159 | end ;
|
||
1160 | 3 : // Curvilin?aire |
||
1161 | begin
|
||
1162 | if RuleLact[i].a = 0 then ok := FALSE ; |
||
1163 | if RuleLact[i].c <= RuleLact[i].a then ok := FALSE ; |
||
1164 | end ;
|
||
1165 | else // Constant |
||
1166 | if RuleLact[i].a = 0 then ok := FALSE ; |
||
1167 | end ;
|
||
1168 | for i := 1 to NbRuleISSF do |
||
1169 | if RuleISSF[i].a = 0 then ok := FALSE ; |
||
1170 | end ;
|
||
1171 | result := ok ; |
||
1172 | end ;
|
||
1173 | |||
1174 | procedure StringsRationT (Liste : TStrings ; IncludeInvalid : Boolean) ;
|
||
1175 | var
|
||
1176 | i : integer ; |
||
1177 | rec : PRecRationT ; |
||
1178 | begin
|
||
1179 | Liste.Clear ; |
||
1180 | if ListRationT.Count > 0 |
||
1181 | then
|
||
1182 | for i := 0 to ListRationT.Count - 1 do |
||
1183 | begin
|
||
1184 | rec := ListRationT[i] ; |
||
1185 | if (IncludeInvalid or RationTValid (rec)) |
||
1186 | // and (IsComplete or (rec.Num <= 5))
|
||
1187 | then
|
||
1188 | Liste.Add (rec.Nom) ; |
||
1189 | end ;
|
||
1190 | end ;
|
||
1191 | |||
1192 | // Logement truie
|
||
1193 | |||
1194 | procedure InitLogeT ;
|
||
1195 | begin
|
||
1196 | ListLogeT := TList.Create ; |
||
1197 | NFicLogeT := 'LogeT.rec' ;
|
||
1198 | end ;
|
||
1199 | |||
1200 | procedure FreeLogeT ;
|
||
1201 | var
|
||
1202 | i : integer ; |
||
1203 | rec : PRecLogeT ; |
||
1204 | begin
|
||
1205 | if ListLogeT.Count > 0 |
||
1206 | then
|
||
1207 | for i := 0 to ListLogeT.Count - 1 do |
||
1208 | begin
|
||
1209 | rec := ListLogeT[i] ; |
||
1210 | Dispose (rec) ; |
||
1211 | end ;
|
||
1212 | ListLogeT.Free ; |
||
1213 | end ;
|
||
1214 | |||
1215 | procedure LoadLogeT ;
|
||
1216 | var
|
||
1217 | i : integer ; |
||
1218 | fic : file of RecLogeT ; |
||
1219 | rec : PRecLogeT ; |
||
1220 | begin
|
||
1221 | // effacement de la liste avant chargement
|
||
1222 | if ListLogeT.Count > 0 |
||
1223 | then
|
||
1224 | for i := 0 to ListLogeT.Count - 1 do |
||
1225 | begin
|
||
1226 | rec := ListLogeT[i] ; |
||
1227 | Dispose (rec) ; |
||
1228 | end ;
|
||
1229 | ListLogeT.Clear ; |
||
1230 | // chargement du fichier
|
||
1231 | if FileExists (NFicLogeT)
|
||
1232 | then
|
||
1233 | begin
|
||
1234 | AssignFile (fic, NFicLogeT) ; |
||
1235 | Reset (fic) ; |
||
1236 | while not Eof (fic) do |
||
1237 | begin
|
||
1238 | New (rec) ; |
||
1239 | Read (fic, rec^) ;
|
||
1240 | ListLogeT.Add (rec) ; |
||
1241 | end ;
|
||
1242 | CloseFile (fic) ; |
||
1243 | end ;
|
||
1244 | end ;
|
||
1245 | |||
1246 | procedure SaveLogeT ;
|
||
1247 | var
|
||
1248 | i : integer ; |
||
1249 | fic : file of RecLogeT ; |
||
1250 | rec : PRecLogeT ; |
||
1251 | begin
|
||
1252 | if not IsComplete and not IsEducation |
||
1253 | then
|
||
1254 | Exit ; |
||
1255 | AssignFile (fic, NFicLogeT) ; |
||
1256 | Rewrite (fic) ; |
||
1257 | if ListLogeT.Count > 0 |
||
1258 | then
|
||
1259 | for i := 0 to ListLogeT.Count - 1 do |
||
1260 | begin
|
||
1261 | rec := ListLogeT[i] ; |
||
1262 | Write (fic, rec^) ;
|
||
1263 | end ;
|
||
1264 | CloseFile (fic) ; |
||
1265 | end ;
|
||
1266 | |||
1267 | function LogeTUsed (Numero : integer) : boolean ;
|
||
1268 | var
|
||
1269 | i : integer ; |
||
1270 | ok : boolean ; |
||
1271 | recProfilT : PRecProfilT ; |
||
1272 | recSimulT : PRecSimulT ; |
||
1273 | begin
|
||
1274 | ok := FALSE ; |
||
1275 | // Utilisation du logement dans un profil animal
|
||
1276 | if ListProfilT.Count > 0 |
||
1277 | then
|
||
1278 | for i := 0 to ListProfilT.Count - 1 do |
||
1279 | begin
|
||
1280 | recProfilT := ListProfilT[i] ; |
||
1281 | if recProfilT.Loge = Numero
|
||
1282 | then
|
||
1283 | ok := TRUE ; |
||
1284 | end ;
|
||
1285 | // Utilisation du logement dans une simulation
|
||
1286 | if ListSimulT.Count > 0 |
||
1287 | then
|
||
1288 | for i := 0 to ListSimulT.Count - 1 do |
||
1289 | begin
|
||
1290 | recSimulT := ListSimulT[i] ; |
||
1291 | if recSimulT.Logement = Numero
|
||
1292 | then
|
||
1293 | ok := TRUE ; |
||
1294 | end ;
|
||
1295 | result := ok ; |
||
1296 | end ;
|
||
1297 | |||
1298 | function LogeTFound (Numero : integer) : boolean ;
|
||
1299 | var
|
||
1300 | i : integer ; |
||
1301 | ok : boolean ; |
||
1302 | recLogeT : PRecLogeT ; |
||
1303 | begin
|
||
1304 | ok := FALSE ; |
||
1305 | i := 0 ;
|
||
1306 | while (i < ListLogeT.Count) and not ok do |
||
1307 | begin
|
||
1308 | recLogeT := ListLogeT[i] ; |
||
1309 | if recLogeT.Num = Numero
|
||
1310 | then
|
||
1311 | ok := TRUE |
||
1312 | else
|
||
1313 | Inc (i) ; |
||
1314 | end ;
|
||
1315 | result := ok ; |
||
1316 | end ;
|
||
1317 | |||
1318 | function LogeTValid (rec : PRecLogeT) : boolean ;
|
||
1319 | begin
|
||
1320 | result := TRUE ; |
||
1321 | end ;
|
||
1322 | |||
1323 | procedure StringsLogeT (Liste : TStrings ; IncludeInvalid : Boolean) ;
|
||
1324 | var
|
||
1325 | i : integer ; |
||
1326 | rec : PRecLogeT ; |
||
1327 | begin
|
||
1328 | Liste.Clear ; |
||
1329 | if ListLogeT.Count > 0 |
||
1330 | then
|
||
1331 | for i := 0 to ListLogeT.Count - 1 do |
||
1332 | begin
|
||
1333 | rec := ListLogeT[i] ; |
||
1334 | if (IncludeInvalid or LogeTValid (rec)) |
||
1335 | // and (IsComplete or (rec.Num <= 5))
|
||
1336 | then
|
||
1337 | Liste.Add (rec.Nom) ; |
||
1338 | end ;
|
||
1339 | end ;
|
||
1340 | |||
1341 | // Profil truie
|
||
1342 | |||
1343 | procedure InitProfilT ;
|
||
1344 | begin
|
||
1345 | ListProfilT := TList.Create ; |
||
1346 | NFicProfilT := 'ProfilT.rec' ;
|
||
1347 | end ;
|
||
1348 | |||
1349 | procedure FreeProfilT ;
|
||
1350 | var
|
||
1351 | i : integer ; |
||
1352 | rec : PRecProfilT ; |
||
1353 | begin
|
||
1354 | if ListProfilT.Count > 0 |
||
1355 | then
|
||
1356 | for i := 0 to ListProfilT.Count - 1 do |
||
1357 | begin
|
||
1358 | rec := ListProfilT[i] ; |
||
1359 | Dispose (rec) ; |
||
1360 | end ;
|
||
1361 | ListProfilT.Free ; |
||
1362 | end ;
|
||
1363 | |||
1364 | procedure LoadProfilT ;
|
||
1365 | var
|
||
1366 | i : integer ; |
||
1367 | fic : file of RecProfilT ; |
||
1368 | rec : PRecProfilT ; |
||
1369 | begin
|
||
1370 | // effacement de la liste avant chargement
|
||
1371 | if ListProfilT.Count > 0 |
||
1372 | then
|
||
1373 | for i := 0 to ListProfilT.Count - 1 do |
||
1374 | begin
|
||
1375 | rec := ListProfilT[i] ; |
||
1376 | Dispose (rec) ; |
||
1377 | end ;
|
||
1378 | ListProfilT.Clear ; |
||
1379 | // chargement du fichier
|
||
1380 | if FileExists (NFicProfilT)
|
||
1381 | then
|
||
1382 | begin
|
||
1383 | AssignFile (fic, NFicProfilT) ; |
||
1384 | Reset (fic) ; |
||
1385 | while not Eof (fic) do |
||
1386 | begin
|
||
1387 | New (rec) ; |
||
1388 | Read (fic, rec^) ;
|
||
1389 | ListProfilT.Add (rec) ; |
||
1390 | end ;
|
||
1391 | CloseFile (fic) ; |
||
1392 | end ;
|
||
1393 | end ;
|
||
1394 | |||
1395 | procedure SaveProfilT ;
|
||
1396 | var
|
||
1397 | i : integer ; |
||
1398 | fic : file of RecProfilT ; |
||
1399 | rec : PRecProfilT ; |
||
1400 | begin
|
||
1401 | if not IsComplete and not IsEducation |
||
1402 | then
|
||
1403 | Exit ; |
||
1404 | AssignFile (fic, NFicProfilT) ; |
||
1405 | Rewrite (fic) ; |
||
1406 | if ListProfilT.Count > 0 |
||
1407 | then
|
||
1408 | for i := 0 to ListProfilT.Count - 1 do |
||
1409 | begin
|
||
1410 | rec := ListProfilT[i] ; |
||
1411 | Write (fic, rec^) ;
|
||
1412 | end ;
|
||
1413 | CloseFile (fic) ; |
||
1414 | end ;
|
||
1415 | |||
1416 | function ProfilTUsed (Numero : integer) : boolean ;
|
||
1417 | var
|
||
1418 | i : integer ; |
||
1419 | ok : boolean ; |
||
1420 | recSimulT : PRecSimulT ; |
||
1421 | begin
|
||
1422 | ok := FALSE ; |
||
1423 | // Utilisation du profil dans une simulation
|
||
1424 | if ListSimulT.Count > 0 |
||
1425 | then
|
||
1426 | for i := 0 to ListSimulT.Count - 1 do |
||
1427 | begin
|
||
1428 | recSimulT := ListSimulT[i] ; |
||
1429 | if recSimulT.Profil = Numero
|
||
1430 | then
|
||
1431 | ok := TRUE ; |
||
1432 | end ;
|
||
1433 | result := ok ; |
||
1434 | end ;
|
||
1435 | |||
1436 | function ProfilTFound (Numero : integer) : boolean ;
|
||
1437 | var
|
||
1438 | i : integer ; |
||
1439 | ok : boolean ; |
||
1440 | recProfilT : PRecProfilT ; |
||
1441 | begin
|
||
1442 | ok := FALSE ; |
||
1443 | i := 0 ;
|
||
1444 | while (i < ListProfilT.Count) and not ok do |
||
1445 | begin
|
||
1446 | recProfilT := ListProfilT[i] ; |
||
1447 | if recProfilT.Num = Numero
|
||
1448 | then
|
||
1449 | ok := TRUE |
||
1450 | else
|
||
1451 | Inc (i) ; |
||
1452 | end ;
|
||
1453 | result := ok ; |
||
1454 | end ;
|
||
1455 | |||
1456 | function ProfilTValid (rec : PRecProfilT) : boolean ;
|
||
1457 | var
|
||
1458 | i : integer ; |
||
1459 | ok : boolean ; |
||
1460 | begin
|
||
1461 | ok := TRUE ; |
||
1462 | with rec^ do |
||
1463 | begin
|
||
1464 | if Truies[1].AgeSail = 0 then ok := FALSE ; |
||
1465 | for i := 2 to NB_CYCLES do |
||
1466 | if Truies[i].AgeSail <= Truies[i - 1].AgeSail + DureeGest + DureeLact |
||
1467 | then ok := FALSE ;
|
||
1468 | for i := 1 to NB_CYCLES do |
||
1469 | begin
|
||
1470 | with Truies[i] do |
||
1471 | begin
|
||
1472 | if PdsSail = 0 then ok := FALSE ; |
||
1473 | if P2Sail = 0 then ok := FALSE ; |
||
1474 | if PdsAvMB <= PdsApMB then ok := FALSE ; |
||
1475 | if PdsApMB <= PdsSail then ok := FALSE ; |
||
1476 | if P2MB <= P2Sail then ok := FALSE ; |
||
1477 | end ;
|
||
1478 | with Porcelets[i] do |
||
1479 | begin
|
||
1480 | if NesTotaux < NesVivants then ok := FALSE ; |
||
1481 | if NesVivants < Sevres then ok := FALSE ; |
||
1482 | if Sevres = 0 then ok := FALSE ; |
||
1483 | if PdsNais = 0 then ok := FALSE ; |
||
1484 | if PdsSev <= PdsNais then ok := FALSE ; |
||
1485 | end ;
|
||
1486 | if Gest[i] = 0 then ok := FALSE ; |
||
1487 | if Lact[i] = 0 then ok := FALSE ; |
||
1488 | end ;
|
||
1489 | if SeqAli = -1 |
||
1490 | then
|
||
1491 | ok := FALSE |
||
1492 | else
|
||
1493 | begin
|
||
1494 | PSeqAliT := ListSeqAliT[FindIdxSeqAliT (FindNomSeqAliT (SeqAli))] ; |
||
1495 | if not SeqAliTValid (PSeqAliT) then ok := FALSE ; |
||
1496 | end ;
|
||
1497 | if Loge = -1 |
||
1498 | then
|
||
1499 | ok := FALSE |
||
1500 | else
|
||
1501 | begin
|
||
1502 | PLogeT := ListLogeT[FindIdxLogeT (FindNomLogeT (Loge))] ; |
||
1503 | if not LogeTValid (PLogeT) then ok := FALSE ; |
||
1504 | end ;
|
||
1505 | end ;
|
||
1506 | result := ok ; |
||
1507 | end ;
|
||
1508 | |||
1509 | procedure StringsProfilT (Liste : TStrings ; IncludeInvalid : Boolean) ;
|
||
1510 | var
|
||
1511 | i : integer ; |
||
1512 | rec : PRecProfilT ; |
||
1513 | begin
|
||
1514 | Liste.Clear ; |
||
1515 | if ListProfilT.Count > 0 |
||
1516 | then
|
||
1517 | for i := 0 to ListProfilT.Count - 1 do |
||
1518 | begin
|
||
1519 | rec := ListProfilT[i] ; |
||
1520 | if (IncludeInvalid or ProfilTValid (rec)) |
||
1521 | // and (IsComplete or (rec.Num <= 5))
|
||
1522 | then
|
||
1523 | Liste.Add (rec.Nom) ; |
||
1524 | end ;
|
||
1525 | end ;
|
||
1526 | |||
1527 | // Simulation truie
|
||
1528 | |||
1529 | procedure InitSimulT ;
|
||
1530 | begin
|
||
1531 | ListSimulT := TList.Create ; |
||
1532 | NFicSimulT := 'SimulT.rec' ;
|
||
1533 | end ;
|
||
1534 | |||
1535 | procedure FreeSimulT ;
|
||
1536 | var
|
||
1537 | i : integer ; |
||
1538 | rec : PRecSimulT ; |
||
1539 | begin
|
||
1540 | if ListSimulT.Count > 0 |
||
1541 | then
|
||
1542 | for i := 0 to ListSimulT.Count - 1 do |
||
1543 | begin
|
||
1544 | rec := ListSimulT[i] ; |
||
1545 | Dispose (rec) ; |
||
1546 | end ;
|
||
1547 | ListSimulT.Free ; |
||
1548 | end ;
|
||
1549 | |||
1550 | procedure LoadSimulT ;
|
||
1551 | var
|
||
1552 | i : integer ; |
||
1553 | fic : file of RecSimulT ; |
||
1554 | rec : PRecSimulT ; |
||
1555 | begin
|
||
1556 | // effacement de la liste avant chargement
|
||
1557 | if ListSimulT.Count > 0 |
||
1558 | then
|
||
1559 | for i := 0 to ListSimulT.Count - 1 do |
||
1560 | begin
|
||
1561 | rec := ListSimulT[i] ; |
||
1562 | Dispose (rec) ; |
||
1563 | end ;
|
||
1564 | ListSimulT.Clear ; |
||
1565 | // chargement du fichier
|
||
1566 | if FileExists (NFicSimulT)
|
||
1567 | then
|
||
1568 | begin
|
||
1569 | AssignFile (fic, NFicSimulT) ; |
||
1570 | Reset (fic) ; |
||
1571 | while not Eof (fic) do |
||
1572 | begin
|
||
1573 | New (rec) ; |
||
1574 | Read (fic, rec^) ;
|
||
1575 | ListSimulT.Add (rec) ; |
||
1576 | end ;
|
||
1577 | CloseFile (fic) ; |
||
1578 | end ;
|
||
1579 | end ;
|
||
1580 | |||
1581 | procedure SaveSimulT ;
|
||
1582 | var
|
||
1583 | i : integer ; |
||
1584 | fic : file of RecSimulT ; |
||
1585 | rec : PRecSimulT ; |
||
1586 | begin
|
||
1587 | if not IsComplete and not IsEducation |
||
1588 | then
|
||
1589 | Exit ; |
||
1590 | AssignFile (fic, NFicSimulT) ; |
||
1591 | Rewrite (fic) ; |
||
1592 | if ListSimulT.Count > 0 |
||
1593 | then
|
||
1594 | for i := 0 to ListSimulT.Count - 1 do |
||
1595 | begin
|
||
1596 | rec := ListSimulT[i] ; |
||
1597 | Write (fic, rec^) ;
|
||
1598 | end ;
|
||
1599 | CloseFile (fic) ; |
||
1600 | end ;
|
||
1601 | |||
1602 | function SimulTValid (rec : PRecSimulT) : boolean ;
|
||
1603 | var
|
||
1604 | ok : boolean ; |
||
1605 | begin
|
||
1606 | ok := TRUE ; |
||
1607 | with rec^ do |
||
1608 | begin
|
||
1609 | if Profil = -1 |
||
1610 | then
|
||
1611 | ok := FALSE |
||
1612 | else
|
||
1613 | begin
|
||
1614 | PProfilT := ListProfilT[FindIdxProfilT (FindNomProfilT (Profil))] ; |
||
1615 | if not ProfilTValid (PProfilT) then ok := FALSE ; |
||
1616 | end ;
|
||
1617 | if Logement = -1 |
||
1618 | then
|
||
1619 | ok := FALSE |
||
1620 | else
|
||
1621 | begin
|
||
1622 | PLogeT := ListLogeT[FindIdxLogeT (FindNomLogeT (Logement))] ; |
||
1623 | if not LogeTValid (PLogeT) then ok := FALSE ; |
||
1624 | end ;
|
||
1625 | end ;
|
||
1626 | result := ok ; |
||
1627 | end ;
|
||
1628 | |||
1629 | procedure StringsSimulT (Liste : TStrings ; IncludeInvalid : Boolean) ;
|
||
1630 | var
|
||
1631 | i : integer ; |
||
1632 | rec : PRecSimulT ; |
||
1633 | begin
|
||
1634 | Liste.Clear ; |
||
1635 | if ListSimulT.Count > 0 |
||
1636 | then
|
||
1637 | for i := 0 to ListSimulT.Count - 1 do |
||
1638 | begin
|
||
1639 | rec := ListSimulT[i] ; |
||
1640 | if (IncludeInvalid or SimulTValid (rec)) |
||
1641 | // and (IsComplete or (rec.Num <= 5))
|
||
1642 | then
|
||
1643 | Liste.Add (rec.Nom) ; |
||
1644 | end ;
|
||
1645 | end ;
|
||
1646 | |||
1647 | // S?quence alimentaire porc
|
||
1648 | |||
1649 | procedure InitSeqAliP ;
|
||
1650 | begin
|
||
1651 | ListSeqAliP := TList.Create ; |
||
1652 | NFicSeqAliP := 'SeqAliP.rec' ;
|
||
1653 | end ;
|
||
1654 | |||
1655 | procedure FreeSeqAliP ;
|
||
1656 | var
|
||
1657 | i : integer ; |
||
1658 | rec : PRecSeqAliP ; |
||
1659 | begin
|
||
1660 | if ListSeqAliP.Count > 0 |
||
1661 | then
|
||
1662 | for i := 0 to ListSeqAliP.Count - 1 do |
||
1663 | begin
|
||
1664 | rec := ListSeqAliP[i] ; |
||
1665 | Dispose (rec) ; |
||
1666 | end ;
|
||
1667 | ListSeqAliP.Free ; |
||
1668 | end ;
|
||
1669 | |||
1670 | procedure LoadSeqAliP ;
|
||
1671 | var
|
||
1672 | i : integer ; |
||
1673 | fic : file of RecSeqAliP ; |
||
1674 | rec : PRecSeqAliP ; |
||
1675 | begin
|
||
1676 | // effacement de la liste avant chargement
|
||
1677 | if ListSeqAliP.Count > 0 |
||
1678 | then
|
||
1679 | for i := 0 to ListSeqAliP.Count - 1 do |
||
1680 | begin
|
||
1681 | rec := ListSeqAliP[i] ; |
||
1682 | Dispose (rec) ; |
||
1683 | end ;
|
||
1684 | ListSeqAliP.Clear ; |
||
1685 | // chargement du fichier
|
||
1686 | if FileExists (NFicSeqAliP)
|
||
1687 | then
|
||
1688 | begin
|
||
1689 | AssignFile (fic, NFicSeqAliP) ; |
||
1690 | Reset (fic) ; |
||
1691 | while not Eof (fic) do |
||
1692 | begin
|
||
1693 | New (rec) ; |
||
1694 | Read (fic, rec^) ;
|
||
1695 | ListSeqAliP.Add (rec) ; |
||
1696 | end ;
|
||
1697 | CloseFile (fic) ; |
||
1698 | end ;
|
||
1699 | end ;
|
||
1700 | |||
1701 | procedure SaveSeqAliP ;
|
||
1702 | var
|
||
1703 | i : integer ; |
||
1704 | fic : file of RecSeqAliP ; |
||
1705 | rec : PRecSeqAliP ; |
||
1706 | begin
|
||
1707 | if not IsComplete and not IsEducation |
||
1708 | then
|
||
1709 | Exit ; |
||
1710 | AssignFile (fic, NFicSeqAliP) ; |
||
1711 | Rewrite (fic) ; |
||
1712 | if ListSeqAliP.Count > 0 |
||
1713 | then
|
||
1714 | for i := 0 to ListSeqAliP.Count - 1 do |
||
1715 | begin
|
||
1716 | rec := ListSeqAliP[i] ; |
||
1717 | Write (fic, rec^) ;
|
||
1718 | end ;
|
||
1719 | CloseFile (fic) ; |
||
1720 | end ;
|
||
1721 | |||
1722 | function SeqAliPUsed (Numero : integer) : boolean ;
|
||
1723 | var
|
||
1724 | i : integer ; |
||
1725 | ok : boolean ; |
||
1726 | recProfilP : PRecProfilP ; |
||
1727 | recSimulP : PRecSimulP ; |
||
1728 | begin
|
||
1729 | ok := FALSE ; |
||
1730 | // Utilisation de la s?quence alimentaire dans un profil animal
|
||
1731 | if ListProfilP.Count > 0 |
||
1732 | then
|
||
1733 | for i := 0 to ListProfilP.Count - 1 do |
||
1734 | begin
|
||
1735 | recProfilP := ListProfilP[i] ; |
||
1736 | if recProfilP.SeqAli = Numero
|
||
1737 | then
|
||
1738 | ok := TRUE ; |
||
1739 | end ;
|
||
1740 | // Utilisation de la s?quence alimentaire dans une simulation
|
||
1741 | if ListSimulP.Count > 0 |
||
1742 | then
|
||
1743 | for i := 0 to ListSimulP.Count - 1 do |
||
1744 | begin
|
||
1745 | recSimulP := ListSimulP[i] ; |
||
1746 | if recSimulP.SeqAli = Numero
|
||
1747 | then
|
||
1748 | ok := TRUE ; |
||
1749 | end ;
|
||
1750 | result := ok ; |
||
1751 | end ;
|
||
1752 | |||
1753 | function SeqAliPFound (Numero : integer) : boolean ;
|
||
1754 | var
|
||
1755 | i : integer ; |
||
1756 | ok : boolean ; |
||
1757 | recSeqAliP : PRecSeqAliP ; |
||
1758 | begin
|
||
1759 | ok := FALSE ; |
||
1760 | i := 0 ;
|
||
1761 | while (i < ListSeqAliP.Count) and not ok do |
||
1762 | begin
|
||
1763 | recSeqAliP := ListSeqAliP[i] ; |
||
1764 | if recSeqAliP.Num = Numero
|
||
1765 | then
|
||
1766 | ok := TRUE |
||
1767 | else
|
||
1768 | Inc (i) ; |
||
1769 | end ;
|
||
1770 | result := ok ; |
||
1771 | end ;
|
||
1772 | |||
1773 | function SeqAliPValid (rec : PRecSeqAliP) : boolean ;
|
||
1774 | var
|
||
1775 | i : integer ; |
||
1776 | ok : boolean ; |
||
1777 | begin
|
||
1778 | ok := TRUE ; |
||
1779 | with rec^ do |
||
1780 | for i := 1 to NbRule do |
||
1781 | if Rule[i].NumAli1 = -1 |
||
1782 | then
|
||
1783 | ok := FALSE |
||
1784 | else
|
||
1785 | begin
|
||
1786 | PAliment := ListAliment[FindIdxAliment (FindNomAliment (Rule[i].NumAli1))] ; |
||
1787 | if not AlimentValid (PAliment) then ok := FALSE ; |
||
1788 | end ;
|
||
1789 | result := ok ; |
||
1790 | end ;
|
||
1791 | |||
1792 | procedure StringsSeqAliP (Liste : TStrings ; IncludeInvalid : Boolean) ;
|
||
1793 | var
|
||
1794 | i : integer ; |
||
1795 | rec : PRecSeqAliP ; |
||
1796 | begin
|
||
1797 | Liste.Clear ; |
||
1798 | if ListSeqAliP.Count > 0 |
||
1799 | then
|
||
1800 | for i := 0 to ListSeqAliP.Count - 1 do |
||
1801 | begin
|
||
1802 | rec := ListSeqAliP[i] ; |
||
1803 | if (IncludeInvalid or SeqAliPValid (rec)) |
||
1804 | // and (IsComplete or (rec.Num <= 5))
|
||
1805 | then
|
||
1806 | Liste.Add (rec.Nom) ; |
||
1807 | end ;
|
||
1808 | end ;
|
||
1809 | |||
1810 | // Plan de rationnement porc
|
||
1811 | |||
1812 | procedure InitRationP ;
|
||
1813 | begin
|
||
1814 | NFicRationPold := 'RationP.rec' ;
|
||
1815 | ListRationP := TList.Create ; |
||
1816 | NFicRationP := 'RationP2.rec' ;
|
||
1817 | end ;
|
||
1818 | |||
1819 | procedure FreeRationP ;
|
||
1820 | var
|
||
1821 | i : integer ; |
||
1822 | rec : PRecRationP ; |
||
1823 | begin
|
||
1824 | if ListRationP.Count > 0 |
||
1825 | then
|
||
1826 | for i := 0 to ListRationP.Count - 1 do |
||
1827 | begin
|
||
1828 | rec := ListRationP[i] ; |
||
1829 | Dispose (rec) ; |
||
1830 | end ;
|
||
1831 | ListRationP.Free ; |
||
1832 | end ;
|
||
1833 | |||
1834 | procedure ConvertRationP2;
|
||
1835 | var
|
||
1836 | i: integer; |
||
1837 | oldfic: file of RecRationPold; |
||
1838 | oldrec: PRecRationPold; |
||
1839 | newfic: file of RecRationP; |
||
1840 | newrec: PRecRationP; |
||
1841 | begin
|
||
1842 | AssignFile(oldfic, NFicRationPold); |
||
1843 | Reset(oldfic); |
||
1844 | New(oldrec); |
||
1845 | while not Eof(oldfic) do |
||
1846 | begin
|
||
1847 | Read(oldfic, oldrec^);
|
||
1848 | New(newrec); |
||
1849 | newrec.Num := oldrec.Num; |
||
1850 | newrec.Nom := oldrec.Nom; |
||
1851 | newrec.Memo := oldrec.Memo; |
||
1852 | newrec.NbRule := oldrec.NbRule; |
||
1853 | for i := 1 to MAX_RULE do |
||
1854 | begin
|
||
1855 | newrec.Rule[i].ModeFin := oldrec.Rule[i].ModeFin; |
||
1856 | newrec.Rule[i].ValFin := oldrec.Rule[i].ValFin; |
||
1857 | newrec.Rule[i].Gaspillage := 0;
|
||
1858 | case oldrec.Rule[i].Equation of |
||
1859 | 2..5: // f(poids vif) |
||
1860 | newrec.Rule[i].RuleType := 3;
|
||
1861 | 6..8: // f(dur?e) |
||
1862 | newrec.Rule[i].RuleType := 2;
|
||
1863 | 9: // % Ad libitum |
||
1864 | newrec.Rule[i].RuleType := 0;
|
||
1865 | else // Ad libitum ou Constant |
||
1866 | newrec.Rule[i].RuleType := oldrec.Rule[i].Equation; |
||
1867 | end;
|
||
1868 | newrec.Rule[i].Unite := oldrec.Rule[i].Unite; |
||
1869 | if newrec.Rule[i].RuleType = 2 |
||
1870 | then // f(dur?e) |
||
1871 | newrec.Rule[i].EqDuree := oldrec.Rule[i].Equation - 7
|
||
1872 | else
|
||
1873 | newrec.Rule[i].EqDuree := -1;
|
||
1874 | if newrec.Rule[i].RuleType = 3 |
||
1875 | then // f(poids vif) |
||
1876 | newrec.Rule[i].EqPV := oldrec.Rule[i].Equation - 3
|
||
1877 | else
|
||
1878 | newrec.Rule[i].EqPV := -1;
|
||
1879 | // Valeurs par d?faut
|
||
1880 | newrec.Rule[i].Percent := 1;
|
||
1881 | newrec.Rule[i].Quantity := 0;
|
||
1882 | newrec.Rule[i].aDuree := 0;
|
||
1883 | newrec.Rule[i].bDuree := 0;
|
||
1884 | newrec.Rule[i].aPV := 0;
|
||
1885 | newrec.Rule[i].bPV := 0;
|
||
1886 | // Valeurs utilis?es
|
||
1887 | case oldrec.Rule[i].Equation of |
||
1888 | 1: // Constant |
||
1889 | newrec.Rule[i].Quantity := oldrec.Rule[i].a; |
||
1890 | 3..5: // f(poids vif) |
||
1891 | begin
|
||
1892 | newrec.Rule[i].aPV := oldrec.Rule[i].a; |
||
1893 | newrec.Rule[i].bPV := oldrec.Rule[i].b; |
||
1894 | end;
|
||
1895 | 7..8: // f(dur?e) |
||
1896 | begin
|
||
1897 | newrec.Rule[i].aDuree := oldrec.Rule[i].a; |
||
1898 | newrec.Rule[i].bDuree := oldrec.Rule[i].b; |
||
1899 | end;
|
||
1900 | 9: // % Ad libitum |
||
1901 | newrec.Rule[i].Percent := oldrec.Rule[i].a; |
||
1902 | end;
|
||
1903 | end ;
|
||
1904 | ListRationP.Add(newrec); |
||
1905 | end;
|
||
1906 | CloseFile(oldfic); |
||
1907 | if not IsComplete and not IsEducation |
||
1908 | then
|
||
1909 | Exit; |
||
1910 | // RenameFile(NFicRationPold, 'RationP.old');
|
||
1911 | // DeleteFile(NFicRationPold);
|
||
1912 | AssignFile(newfic, NFicRationP); |
||
1913 | Rewrite(newfic); |
||
1914 | if ListRationP.Count > 0 |
||
1915 | then
|
||
1916 | for i := 0 to ListRationP.Count - 1 do |
||
1917 | begin
|
||
1918 | newrec := ListRationP[i]; |
||
1919 | Write(newfic, newrec^);
|
||
1920 | end;
|
||
1921 | CloseFile(newfic); |
||
1922 | end;
|
||
1923 | |||
1924 | procedure LoadRationP ;
|
||
1925 | var
|
||
1926 | i : integer ; |
||
1927 | fic : file of RecRationP ; |
||
1928 | rec : PRecRationP ; |
||
1929 | begin
|
||
1930 | // effacement de la liste avant chargement
|
||
1931 | if ListRationP.Count > 0 |
||
1932 | then
|
||
1933 | for i := 0 to ListRationP.Count - 1 do |
||
1934 | begin
|
||
1935 | rec := ListRationP[i] ; |
||
1936 | Dispose (rec) ; |
||
1937 | end ;
|
||
1938 | ListRationP.Clear ; |
||
1939 | if not FileExists(NFicRationP) and FileExists(NFicRationPold) and ConvertData |
||
1940 | then // Conversion |
||
1941 | ConvertRationP2 |
||
1942 | else // chargement du fichier |
||
1943 | if FileExists (NFicRationP)
|
||
1944 | then
|
||
1945 | begin
|
||
1946 | AssignFile (fic, NFicRationP) ; |
||
1947 | Reset (fic) ; |
||
1948 | while not Eof (fic) do |
||
1949 | begin
|
||
1950 | New (rec) ; |
||
1951 | Read (fic, rec^) ;
|
||
1952 | ListRationP.Add (rec) ; |
||
1953 | end ;
|
||
1954 | CloseFile (fic) ; |
||
1955 | end ;
|
||
1956 | end ;
|
||
1957 | |||
1958 | procedure SaveRationP ;
|
||
1959 | var
|
||
1960 | i : integer ; |
||
1961 | fic : file of RecRationP ; |
||
1962 | rec : PRecRationP ; |
||
1963 | begin
|
||
1964 | if not IsComplete and not IsEducation |
||
1965 | then
|
||
1966 | Exit ; |
||
1967 | AssignFile (fic, NFicRationP) ; |
||
1968 | Rewrite (fic) ; |
||
1969 | if ListRationP.Count > 0 |
||
1970 | then
|
||
1971 | for i := 0 to ListRationP.Count - 1 do |
||
1972 | begin
|
||
1973 | rec := ListRationP[i] ; |
||
1974 | Write (fic, rec^) ;
|
||
1975 | end ;
|
||
1976 | CloseFile (fic) ; |
||
1977 | end ;
|
||
1978 | |||
1979 | function RationPUsed (Numero : integer) : boolean ;
|
||
1980 | var
|
||
1981 | i : integer ; |
||
1982 | ok : boolean ; |
||
1983 | recProfilP : PRecProfilP ; |
||
1984 | recSimulP : PRecSimulP ; |
||
1985 | begin
|
||
1986 | ok := FALSE ; |
||
1987 | // Utilisation du plan de rationnement dans un profil animal
|
||
1988 | if ListProfilP.Count > 0 |
||
1989 | then
|
||
1990 | for i := 0 to ListProfilP.Count - 1 do |
||
1991 | begin
|
||
1992 | recProfilP := ListProfilP[i] ; |
||
1993 | if recProfilP.Ration = Numero
|
||
1994 | then
|
||
1995 | ok := TRUE ; |
||
1996 | end ;
|
||
1997 | // Utilisation du plan de rationnement dans une simulation
|
||
1998 | if ListSimulP.Count > 0 |
||
1999 | then
|
||
2000 | for i := 0 to ListSimulP.Count - 1 do |
||
2001 | begin
|
||
2002 | recSimulP := ListSimulP[i] ; |
||
2003 | if recSimulP.Ration = Numero
|
||
2004 | then
|
||
2005 | ok := TRUE ; |
||
2006 | end ;
|
||
2007 | result := ok ; |
||
2008 | end ;
|
||
2009 | |||
2010 | function RationPFound (Numero : integer) : boolean ;
|
||
2011 | var
|
||
2012 | i : integer ; |
||
2013 | ok : boolean ; |
||
2014 | recRationP : PRecRationP ; |
||
2015 | begin
|
||
2016 | ok := FALSE ; |
||
2017 | i := 0 ;
|
||
2018 | while (i < ListRationP.Count) and not ok do |
||
2019 | begin
|
||
2020 | recRationP := ListRationP[i] ; |
||
2021 | if recRationP.Num = Numero
|
||
2022 | then
|
||
2023 | ok := TRUE |
||
2024 | else
|
||
2025 | Inc (i) ; |
||
2026 | end ;
|
||
2027 | result := ok ; |
||
2028 | end ;
|
||
2029 | |||
2030 | function RationPValid(rec: PRecRationP): boolean;
|
||
2031 | var
|
||
2032 | i: integer; |
||
2033 | ok: boolean; |
||
2034 | begin
|
||
2035 | ok := True; |
||
2036 | with rec^ do |
||
2037 | for i := 1 to NbRule do |
||
2038 | with Rule[i] do |
||
2039 | begin
|
||
2040 | if (ModeFin = -1) and (i < NbRule) then ok := False; |
||
2041 | case RuleType of |
||
2042 | 0: // % AdLib |
||
2043 | if Percent <= 0 then ok := False; |
||
2044 | 1: // Constant |
||
2045 | begin
|
||
2046 | if Unite = -1 then ok := False; |
||
2047 | if Quantity <= 0 then ok := False; |
||
2048 | end;
|
||
2049 | 2: // f(dur?e) |
||
2050 | begin
|
||
2051 | if Unite = -1 then ok := False; |
||
2052 | if EqDuree = -1 then ok := False; |
||
2053 | if aDuree <= 0 then ok := False; |
||
2054 | if bDuree <= 0 then ok := False; |
||
2055 | end;
|
||
2056 | 3: // f(poids vif) |
||
2057 | begin
|
||
2058 | if Unite = -1 then ok := False; |
||
2059 | case EqPV of |
||
2060 | 0: // Mod?le lin?aire |
||
2061 | begin
|
||
2062 | if bPV <= 0 then ok := False; |
||
2063 | end;
|
||
2064 | 1: // Mod?le puissance |
||
2065 | begin
|
||
2066 | if aPV <= 0 then ok := False; |
||
2067 | if bPV <= 0 then ok := False; |
||
2068 | end;
|
||
2069 | 2: // Mod?le exponentiel |
||
2070 | begin
|
||
2071 | if aPV <= 0 then ok := False; |
||
2072 | if bPV <= 0 then ok := False; |
||
2073 | end;
|
||
2074 | else
|
||
2075 | ok := False; |
||
2076 | end;
|
||
2077 | end;
|
||
2078 | else
|
||
2079 | ok := False; |
||
2080 | end;
|
||
2081 | end;
|
||
2082 | result := ok; |
||
2083 | end;
|
||
2084 | |||
2085 | procedure StringsRationP (Liste : TStrings ; IncludeInvalid : Boolean) ;
|
||
2086 | var
|
||
2087 | i : integer ; |
||
2088 | rec : PRecRationP ; |
||
2089 | begin
|
||
2090 | Liste.Clear ; |
||
2091 | if ListRationP.Count > 0 |
||
2092 | then
|
||
2093 | for i := 0 to ListRationP.Count - 1 do |
||
2094 | begin
|
||
2095 | rec := ListRationP[i] ; |
||
2096 | if (IncludeInvalid or RationPValid (rec)) |
||
2097 | // and (IsComplete or (rec.Num <= 5))
|
||
2098 | then
|
||
2099 | Liste.Add (rec.Nom) ; |
||
2100 | end ;
|
||
2101 | end ;
|
||
2102 | |||
2103 | // Profil porc
|
||
2104 | |||
2105 | procedure InitProfilP;
|
||
2106 | begin
|
||
2107 | NFicProfilPold := 'ProfilP.rec';
|
||
2108 | ListProfilP := TList.Create; |
||
2109 | NFicProfilP := 'ProfilP2.rec';
|
||
2110 | end;
|
||
2111 | |||
2112 | procedure FreeProfilP;
|
||
2113 | var
|
||
2114 | i: integer; |
||
2115 | rec: PRecProfilP; |
||
2116 | begin
|
||
2117 | if ListProfilP.Count > 0 |
||
2118 | then
|
||
2119 | for i := 0 to ListProfilP.Count - 1 do |
||
2120 | begin
|
||
2121 | rec := ListProfilP[i]; |
||
2122 | Dispose(rec); |
||
2123 | end;
|
||
2124 | ListProfilP.Free; |
||
2125 | end;
|
||
2126 | |||
2127 | procedure ConvertProfilP2;
|
||
2128 | var
|
||
2129 | i: integer; |
||
2130 | oldfic: file of RecProfilPold; |
||
2131 | oldrec: PRecProfilPold; |
||
2132 | newfic: file of RecProfilP; |
||
2133 | newrec: PRecProfilP; |
||
2134 | begin
|
||
2135 | AssignFile(oldfic, NFicProfilPold); |
||
2136 | Reset(oldfic); |
||
2137 | New(oldrec); |
||
2138 | while not Eof(oldfic) do |
||
2139 | begin
|
||
2140 | Read(oldfic, oldrec^);
|
||
2141 | New(newrec); |
||
2142 | newrec.Num := oldrec.Num; |
||
2143 | newrec.Nom := oldrec.Nom; |
||
2144 | newrec.Memo := oldrec.Memo; |
||
2145 | newrec.Sexe := -1;
|
||
2146 | // Conditions d'?levage
|
||
2147 | newrec.SeqAli := oldrec.SeqAli ; |
||
2148 | newrec.Ration := -1;
|
||
2149 | newrec.AgeInit := oldrec.AgeInit ; |
||
2150 | newrec.PVInit := oldrec.PVInit ; |
||
2151 | newrec.ProtInit := oldrec.ProtInit; |
||
2152 | newrec.LipInit := oldrec.LipInit; |
||
2153 | newrec.ModeFin := oldrec.ModeFin ; |
||
2154 | newrec.Duree := oldrec.Duree ; |
||
2155 | newrec.PVFin := oldrec.PVFin ; |
||
2156 | newrec.Carcasse := oldrec.Carcasse ; |
||
2157 | // Consommation et performances ad libitum
|
||
2158 | newrec.Unite := oldrec.Unite ; |
||
2159 | newrec.Equation := oldrec.Equation ; |
||
2160 | newrec.a := oldrec.a; |
||
2161 | newrec.b := oldrec.b; |
||
2162 | newrec.PDMoy := oldrec.PDMoy ; |
||
2163 | newrec.BGompertz := oldrec.BGompertz ; |
||
2164 | newrec.Entretien := oldrec.Entretien ; |
||
2165 | // R?ponse ? une restriction alimentaire
|
||
2166 | newrec.PVmr2 := oldrec.PVmr2 ; |
||
2167 | ListProfilP.Add(newrec); |
||
2168 | end;
|
||
2169 | CloseFile(oldfic); |
||
2170 | if not IsComplete and not IsEducation |
||
2171 | then
|
||
2172 | Exit; |
||
2173 | // RenameFile(NFicProfilPold, 'ProfilP.old');
|
||
2174 | // DeleteFile(NFicProfilPold);
|
||
2175 | AssignFile(newfic, NFicProfilP); |
||
2176 | Rewrite(newfic); |
||
2177 | if ListProfilP.Count > 0 |
||
2178 | then
|
||
2179 | for i := 0 to ListProfilP.Count - 1 do |
||
2180 | begin
|
||
2181 | newrec := ListProfilP[i]; |
||
2182 | Write(newfic, newrec^);
|
||
2183 | end;
|
||
2184 | CloseFile(newfic); |
||
2185 | end;
|
||
2186 | |||
2187 | procedure LoadProfilP;
|
||
2188 | var
|
||
2189 | i: integer; |
||
2190 | fic: file of RecProfilP; |
||
2191 | rec: PRecPRofilP; |
||
2192 | begin
|
||
2193 | // effacement de la liste avant chargement
|
||
2194 | if ListProfilP.Count > 0 |
||
2195 | then
|
||
2196 | for i := 0 to ListProfilP.Count - 1 do |
||
2197 | begin
|
||
2198 | rec := ListProfilP[i]; |
||
2199 | Dispose(rec); |
||
2200 | end ;
|
||
2201 | ListProfilP.Clear; |
||
2202 | if not FileExists(NFicProfilP) and FileExists(NFicProfilPold) and ConvertData |
||
2203 | then // Conversion |
||
2204 | ConvertProfilP2 |
||
2205 | else // chargement du fichier |
||
2206 | if FileExists(NFicProfilP)
|
||
2207 | then
|
||
2208 | begin
|
||
2209 | AssignFile(fic, NFicProfilP); |
||
2210 | Reset(fic); |
||
2211 | while not Eof(fic) do |
||
2212 | begin
|
||
2213 | New(rec); |
||
2214 | Read(fic, rec^);
|
||
2215 | ListProfilP.Add(rec); |
||
2216 | end;
|
||
2217 | CloseFile(fic); |
||
2218 | end;
|
||
2219 | end;
|
||
2220 | |||
2221 | procedure SaveProfilP;
|
||
2222 | var
|
||
2223 | i: integer; |
||
2224 | fic: file of RecProfilP; |
||
2225 | rec: PRecProfilP; |
||
2226 | begin
|
||
2227 | if not IsComplete and not IsEducation |
||
2228 | then
|
||
2229 | Exit; |
||
2230 | AssignFile(fic, NFicProfilP); |
||
2231 | Rewrite(fic); |
||
2232 | if ListProfilP.Count > 0 |
||
2233 | then
|
||
2234 | for i := 0 to ListProfilP.Count - 1 do |
||
2235 | begin
|
||
2236 | rec := ListProfilP[i]; |
||
2237 | Write(fic, rec^);
|
||
2238 | end;
|
||
2239 | CloseFile(fic); |
||
2240 | end;
|
||
2241 | |||
2242 | function ProfilPUsed(Numero: integer): boolean;
|
||
2243 | var
|
||
2244 | i: integer; |
||
2245 | ok: boolean; |
||
2246 | recSimulP: PRecSimulP; |
||
2247 | begin
|
||
2248 | ok := False; |
||
2249 | // Utilisation du profil dans une simulation
|
||
2250 | if ListSimulP.Count > 0 |
||
2251 | then
|
||
2252 | for i := 0 to ListSimulP.Count - 1 do |
||
2253 | begin
|
||
2254 | recSimulP := ListSimulP[i]; |
||
2255 | if recSimulP.Profil = Numero
|
||
2256 | then
|
||
2257 | ok := True; |
||
2258 | end;
|
||
2259 | result := ok; |
||
2260 | end;
|
||
2261 | |||
2262 | function ProfilPFound(Numero: integer): boolean;
|
||
2263 | var
|
||
2264 | i: integer; |
||
2265 | ok: boolean; |
||
2266 | recProfilP: PRecProfilP; |
||
2267 | begin
|
||
2268 | ok := False; |
||
2269 | i := 0;
|
||
2270 | while (i < ListProfilP.Count) and not ok do |
||
2271 | begin
|
||
2272 | recProfilP := ListProfilP[i]; |
||
2273 | if recProfilP.Num = Numero
|
||
2274 | then
|
||
2275 | ok := True |
||
2276 | else
|
||
2277 | Inc(i); |
||
2278 | end ;
|
||
2279 | result := ok; |
||
2280 | end;
|
||
2281 | |||
2282 | function ProfilPValid(rec: PRecProfilP): boolean;
|
||
2283 | var
|
||
2284 | ok: boolean; |
||
2285 | T1, T2: Double; |
||
2286 | begin
|
||
2287 | ok := True; |
||
2288 | with rec^ do |
||
2289 | begin
|
||
2290 | {
|
||
2291 | if SeqAli = -1
|
||
2292 | then
|
||
2293 | ok := False
|
||
2294 | else
|
||
2295 | begin
|
||
2296 | PSeqAliP := ListSeqAliP[FindIdxSeqAliP(FindNomSeqAliP(SeqAli))];
|
||
2297 | if not SeqAliPValid(PSeqAliP) then ok := False;
|
||
2298 | end;
|
||
2299 | }
|
||
2300 | if ProtInit <= 0 then ok := False; |
||
2301 | if LipInit <= 0 then ok := False; |
||
2302 | if Unite = -1 then ok := False; |
||
2303 | case Equation of |
||
2304 | 0: // Mod?le lin?aire |
||
2305 | begin
|
||
2306 | if b <= 0 then ok := False; |
||
2307 | if CalcIngere(0, Unite, a, b, PVInit) <= 0 then ok := False; |
||
2308 | end;
|
||
2309 | 1: // Mod?le puissance |
||
2310 | begin
|
||
2311 | if a <= 0 then ok := False; |
||
2312 | if b <= 0 then ok := False; |
||
2313 | if CalcIngere(1, Unite, a, b, PVInit) <= 0 then ok := False; |
||
2314 | end;
|
||
2315 | 2: // Mod?le exponentiel |
||
2316 | begin
|
||
2317 | if a <= 0 then ok := False; |
||
2318 | if b <= 0 then ok := False; |
||
2319 | if CalcIngere(2, Unite, a, b, PVInit) <= 0 then ok := False; |
||
2320 | end;
|
||
2321 | 3: // Mod?le Gamma |
||
2322 | begin
|
||
2323 | if a <= 0 then ok := False; |
||
2324 | if b <= 0 then ok := False; |
||
2325 | case Unite of |
||
2326 | 0: // Quantit? (kg/j) |
||
2327 | begin
|
||
2328 | T1 := -CalcIngere(3, Unite, a, b, 100) + cGammaFrais * Exp(Ln(100) * dGamma); |
||
2329 | T2 := -CalcIngere(3, Unite, a, b, 50) + cGammaFrais * Exp(Ln(50) * dGamma); |
||
2330 | end;
|
||
2331 | 1: // ED (MJ/j) |
||
2332 | begin
|
||
2333 | T1 := -CalcIngere(3, Unite, a, b, 100) + cGammaED * Exp(Ln(100) * dGamma); |
||
2334 | T2 := -CalcIngere(3, Unite, a, b, 50) + cGammaED * Exp(Ln(50) * dGamma); |
||
2335 | end;
|
||
2336 | 2: // EM (MJ/j) |
||
2337 | begin
|
||
2338 | T1 := -CalcIngere(3, Unite, a, b, 100) + cGammaEM * Exp(Ln(100) * dGamma); |
||
2339 | T2 := -CalcIngere(3, Unite, a, b, 50) + cGammaEM * Exp(Ln(50) * dGamma); |
||
2340 | end;
|
||
2341 | 3: // EN (MJ/j) |
||
2342 | begin
|
||
2343 | T1 := -CalcIngere(3, Unite, a, b, 100) + cGammaEN * Exp(Ln(100) * dGamma); |
||
2344 | T2 := -CalcIngere(3, Unite, a, b, 50) + cGammaEN * Exp(Ln(50) * dGamma); |
||
2345 | end;
|
||
2346 | 4: // MS (kg/j) |
||
2347 | begin
|
||
2348 | T1 := -CalcIngere(3, Unite, a, b, 100) + cGammaMS * Exp(Ln(100) * dGamma); |
||
2349 | T2 := -CalcIngere(3, Unite, a, b, 50) + cGammaMS * Exp(Ln(50) * dGamma); |
||
2350 | end;
|
||
2351 | else
|
||
2352 | begin
|
||
2353 | T1 := 0;
|
||
2354 | T2 := 0;
|
||
2355 | end;
|
||
2356 | end;
|
||
2357 | if T1 = 0 then ok := False; |
||
2358 | if T2 = 0 then ok := False; |
||
2359 | if (T1 > 0) and (T2 < 0) then ok := False; |
||
2360 | if (T1 < 0) and (T2 > 0) then ok := False; |
||
2361 | end;
|
||
2362 | else
|
||
2363 | ok := False; |
||
2364 | end;
|
||
2365 | end;
|
||
2366 | result := ok; |
||
2367 | end;
|
||
2368 | |||
2369 | procedure StringsProfilP(Liste: TStrings; IncludeInvalid: Boolean);
|
||
2370 | var
|
||
2371 | i: integer; |
||
2372 | rec: PRecProfilP; |
||
2373 | begin
|
||
2374 | Liste.Clear; |
||
2375 | if ListProfilP.Count > 0 |
||
2376 | then
|
||
2377 | for i := 0 to ListProfilP.Count - 1 do |
||
2378 | begin
|
||
2379 | rec := ListProfilP[i]; |
||
2380 | if (IncludeInvalid or ProfilPValid(rec)) |
||
2381 | // and (IsComplete or (rec.Num <= 5))
|
||
2382 | then
|
||
2383 | Liste.Add(rec.Nom); |
||
2384 | end;
|
||
2385 | end;
|
||
2386 | |||
2387 | // Simulation porc
|
||
2388 | |||
2389 | procedure InitSimulP ;
|
||
2390 | begin
|
||
2391 | ListSimulP := TList.Create ; |
||
2392 | NFicSimulP := 'SimulP.rec' ;
|
||
2393 | end ;
|
||
2394 | |||
2395 | procedure FreeSimulP ;
|
||
2396 | var
|
||
2397 | i : integer ; |
||
2398 | rec : PRecSimulP ; |
||
2399 | begin
|
||
2400 | if ListSimulP.Count > 0 |
||
2401 | then
|
||
2402 | for i := 0 to ListSimulP.Count - 1 do |
||
2403 | begin
|
||
2404 | rec := ListSimulP[i] ; |
||
2405 | Dispose (rec) ; |
||
2406 | end ;
|
||
2407 | ListSimulP.Free ; |
||
2408 | end ;
|
||
2409 | |||
2410 | procedure LoadSimulP ;
|
||
2411 | var
|
||
2412 | i : integer ; |
||
2413 | fic : file of RecSimulP ; |
||
2414 | rec : PRecSimulP ; |
||
2415 | begin
|
||
2416 | // effacement de la liste avant chargement
|
||
2417 | if ListSimulP.Count > 0 |
||
2418 | then
|
||
2419 | for i := 0 to ListSimulP.Count - 1 do |
||
2420 | begin
|
||
2421 | rec := ListSimulP[i] ; |
||
2422 | Dispose (rec) ; |
||
2423 | end ;
|
||
2424 | ListSimulP.Clear ; |
||
2425 | // chargement du fichier
|
||
2426 | if FileExists (NFicSimulP)
|
||
2427 | then
|
||
2428 | begin
|
||
2429 | AssignFile (fic, NFicSimulP) ; |
||
2430 | Reset (fic) ; |
||
2431 | while not Eof (fic) do |
||
2432 | begin
|
||
2433 | New (rec) ; |
||
2434 | Read (fic, rec^) ;
|
||
2435 | ListSimulP.Add (rec) ; |
||
2436 | end ;
|
||
2437 | CloseFile (fic) ; |
||
2438 | end ;
|
||
2439 | end ;
|
||
2440 | |||
2441 | procedure SaveSimulP ;
|
||
2442 | var
|
||
2443 | i : integer ; |
||
2444 | fic : file of RecSimulP ; |
||
2445 | rec : PRecSimulP ; |
||
2446 | begin
|
||
2447 | if not IsComplete and not IsEducation |
||
2448 | then
|
||
2449 | Exit ; |
||
2450 | AssignFile (fic, NFicSimulP) ; |
||
2451 | Rewrite (fic) ; |
||
2452 | if ListSimulP.Count > 0 |
||
2453 | then
|
||
2454 | for i := 0 to ListSimulP.Count - 1 do |
||
2455 | begin
|
||
2456 | rec := ListSimulP[i] ; |
||
2457 | Write (fic, rec^) ;
|
||
2458 | end ;
|
||
2459 | CloseFile (fic) ; |
||
2460 | end ;
|
||
2461 | |||
2462 | function SimulPValid (rec : PRecSimulP) : boolean ;
|
||
2463 | var
|
||
2464 | ok : boolean ; |
||
2465 | begin
|
||
2466 | ok := TRUE ; |
||
2467 | with rec^ do |
||
2468 | begin
|
||
2469 | if Profil = -1 |
||
2470 | then
|
||
2471 | ok := FALSE |
||
2472 | else
|
||
2473 | begin
|
||
2474 | PProfilP := ListProfilP[FindIdxProfilP (FindNomProfilP (Profil))] ; |
||
2475 | if not ProfilPValid (PProfilP) then ok := FALSE ; |
||
2476 | end ;
|
||
2477 | if SeqAli = -1 |
||
2478 | then
|
||
2479 | ok := FALSE |
||
2480 | else
|
||
2481 | begin
|
||
2482 | PSeqAliP := ListSeqAliP[FindIdxSeqAliP (FindNomSeqAliP (SeqAli))] ; |
||
2483 | if not SeqAliPValid (PSeqAliP) then ok := FALSE ; |
||
2484 | end ;
|
||
2485 | if Ration = -1 |
||
2486 | then
|
||
2487 | ok := FALSE |
||
2488 | else
|
||
2489 | begin
|
||
2490 | PRationP := ListRationP[FindIdxRationP (FindNomRationP (Ration))] ; |
||
2491 | if not RationPValid (PRationP) then ok := FALSE ; |
||
2492 | end ;
|
||
2493 | end ;
|
||
2494 | result := ok ; |
||
2495 | end ;
|
||
2496 | |||
2497 | procedure StringsSimulP (Liste : TStrings ; IncludeInvalid : Boolean) ;
|
||
2498 | var
|
||
2499 | i : integer ; |
||
2500 | rec : PRecSimulP ; |
||
2501 | begin
|
||
2502 | Liste.Clear ; |
||
2503 | if ListSimulP.Count > 0 |
||
2504 | then
|
||
2505 | for i := 0 to ListSimulP.Count - 1 do |
||
2506 | begin
|
||
2507 | rec := ListSimulP[i] ; |
||
2508 | if (IncludeInvalid or SimulPValid (rec)) |
||
2509 | // and (IsComplete or (rec.Num <= 5))
|
||
2510 | then
|
||
2511 | Liste.Add (rec.Nom) ; |
||
2512 | end ;
|
||
2513 | end ;
|
||
2514 | |||
2515 | end. |