algodritmo

masterform

Dec 15th, 2021
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 252.36 KB | None | 0 0
  1. unit MasterForm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   Buttons, ExtCtrls, RumenGut,Microbes, StdCtrls,Math,Utils,
  8.   Global,DateUtils,Printers, Mask, DBCtrls, ComCtrls,strutils, Menus,Save,
  9.   IniFiles, IDGlobal, ShellApi, PDF_In_The_BoxCtl_TLB,System.UITypes, FireDAC.Stan.Intf,
  10.   FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf,
  11.   FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,
  12.   {FireDAC.Phys.DB2,} FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
  13.   FireDAC.DApt, FireDAC.VCLUI.Wait, FireDAC.Comp.UI, FireDAC.Phys.ODBCBase,
  14.   FireDAC.Comp.Client, FireDAC.Comp.DataSet, Data.DB, FireDAC.Stan.ExprFuncs,Variants,
  15.   {FireDAC.Phys.DB2Def,  }Vcl.OleCtrls, FireDAC.Phys.MySQLDef, FireDAC.Phys.MySQL,
  16.   FireDAC.VCLUI.Login,lpsolve;
  17.  
  18. type
  19.  TNonChecked=array[1..16] of Integer;
  20.  
  21. type
  22.  TCategory = record
  23.   Category,FName: array[1..18] of String;
  24.   FAmount,FPrice: array[1..18] of Single;
  25. end;
  26.  
  27. type
  28. TFeedName=record
  29.   ForageID: Integer;
  30.   FeedNameString: String;
  31. end;
  32.  
  33. type
  34.  TWC=record
  35.   WC_Country,WC_Currency,WC_Abbrev,WC_ISO,WC_Cent: array[1..225] of UnicodeString;
  36.   WC_Fraction: array[1..225] of Integer;
  37. end;
  38.  
  39.  
  40. type
  41.   TMain = class(TForm)
  42.     Panel1: TPanel;
  43.     SpeedButton3: TSpeedButton;
  44.     btnRun: TSpeedButton;
  45.     SpeedButton1: TSpeedButton;
  46.     SpeedButton5: TSpeedButton;
  47.     SpeedButton6: TSpeedButton;
  48.     SpeedButton7: TSpeedButton;
  49.     MainMenu1: TMainMenu;
  50.     File1: TMenuItem;
  51.     Maintenance1: TMenuItem;
  52.     Quit1: TMenuItem;
  53.     SaveDialog1: TSaveDialog;
  54.     Help1: TMenuItem;
  55.     SpeedButton4: TSpeedButton;
  56.     PrinterSetup1: TMenuItem;
  57.     PrinterSetupDialog1: TPrinterSetupDialog;
  58.     SpeedButton8: TSpeedButton;
  59.     PrintDialog1: TPrintDialog;
  60.     SpeedButton10: TSpeedButton;
  61.     Open1: TMenuItem;
  62.     SaveAs1: TMenuItem;
  63.     L1: TMenuItem;
  64.     Feeds1: TMenuItem;
  65.     ViewProtein1: TMenuItem;
  66.     ViewEnergy1: TMenuItem;
  67.     ModelOptions1: TMenuItem;
  68.     StatusBar1: TStatusBar;
  69.     NewFarmer1: TMenuItem;
  70.     PreMixes1: TMenuItem;
  71.     About1: TMenuItem;
  72.     SpeedButton11: TSpeedButton;
  73.     ShowAddFeedIngredients1: TMenuItem;
  74.     DeleteaFeed1: TMenuItem;
  75.     DeleteaPreMix1: TMenuItem;
  76.     SetIngPrice: TMenuItem;
  77.     AutoCreatePreMix1: TMenuItem;
  78.     ViewMGP1: TMenuItem;
  79.     Analysebcp1: TMenuItem;
  80.     Optimize1: TMenuItem;
  81.     ModifyRates1: TMenuItem;
  82.     FDConnection1: TFDConnection;
  83.     FDQuery1: TFDQuery;
  84.     FDTable1: TFDTable;
  85.     FDGUIxWaitCursor1: TFDGUIxWaitCursor;
  86.     WhatIf1: TMenuItem;
  87.     WhatIf2: TMenuItem;
  88.     Admin1: TMenuItem;
  89.     Update1: TMenuItem;
  90.     FromDatabase1: TMenuItem;
  91.     pH6Help11: TMenuItem;
  92.     ForagesfromDatabase1: TMenuItem;
  93.     AdjustfNDF1: TMenuItem;
  94.     AddForage1: TMenuItem;
  95.     RestrictDB1: TMenuItem;
  96.     PdfBox1: TPdfBox;
  97.     Label1: TLabel;
  98.     Enlarge1: TMenuItem;
  99.     ShowGraphs1: TMenuItem;
  100.     ShowDiet1: TMenuItem;
  101.     ShowMilk1: TMenuItem;
  102.     ShowNutrients1: TMenuItem;
  103.     ShowRumenFunctions1: TMenuItem;
  104.     ShowMinerals1: TMenuItem;
  105.     FDPhysMySQLDriverLink1: TFDPhysMySQLDriverLink;
  106.     Currency1: TMenuItem;
  107.     Memo1: TMemo;
  108.     procedure SpeedButton3Click(Sender: TObject);
  109.     procedure btnRunClick(Sender: TObject);
  110.     procedure FormCreate(Sender: TObject);
  111.     procedure SpeedButton1Click(Sender: TObject);
  112.     procedure SpeedButton6Click(Sender: TObject);
  113.     procedure SpeedButton7Click(Sender: TObject);
  114.     procedure SpeedButton8Click(Sender: TObject);
  115.     procedure Quit1Click(Sender: TObject);
  116.     procedure SpeedButton4Click(Sender: TObject);
  117.     procedure PrinterSetup1Click(Sender: TObject);
  118. //    procedure SpeedButton9Click(Sender: TObject);
  119.     procedure SpeedButton10Click(Sender: TObject);
  120.     procedure Open1Click(Sender: TObject);
  121.     procedure Save1Click(Sender: TObject);
  122.     procedure SaveAs1Click(Sender: TObject);
  123.     procedure L1Click(Sender: TObject);
  124.     procedure ReadLanguage;
  125.     procedure ViewProtein1Click(Sender: TObject);
  126.     procedure ViewEnergy1Click(Sender: TObject);
  127.     procedure FormDestroy(Sender: TObject);
  128.     procedure ModelOptions1Click(Sender: TObject);
  129.     procedure NewFarmer1Click(Sender: TObject);
  130.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  131.     procedure PreMixes1Click(Sender: TObject);
  132.     procedure About1Click(Sender: TObject);
  133.     procedure SpeedButton11Click(Sender: TObject);
  134.     procedure ShowAddFeedIngredients1Click(Sender: TObject);
  135.     procedure DeleteaFeed1Click(Sender: TObject);
  136.     procedure DeleteaPreMix1Click(Sender: TObject);
  137.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  138.     procedure SetIngPriceClick(Sender: TObject);
  139.     procedure AutoCreatePreMix1Click(Sender: TObject);
  140.     procedure ViewMGP1Click(Sender: TObject);
  141.     procedure Analysebcp1Click(Sender: TObject);
  142.     procedure Optimize1Click(Sender: TObject);
  143.     procedure ModifyRates1Click(Sender: TObject);
  144.     procedure WhatIf2Click(Sender: TObject);
  145.     procedure Admin1Click(Sender: TObject);
  146.     procedure FromDatabase1Click(Sender: TObject);
  147.     procedure pH6Help11Click(Sender: TObject);
  148.     procedure ForagesfromDatabase1Click(Sender: TObject);
  149.     procedure AdjustfNDF1Click(Sender: TObject);
  150.     procedure AddForage1Click(Sender: TObject);
  151.     procedure RestrictDB1Click(Sender: TObject);
  152.     procedure TrackBar1EndDrag(Sender, Target: TObject; X, Y: Integer);
  153.     procedure Enlarge1Click(Sender: TObject);
  154.     procedure ShowGraphs1Click(Sender: TObject);
  155.     procedure ShowDiet1Click(Sender: TObject);
  156.     procedure ShowMilk1Click(Sender: TObject);
  157.     procedure ShowNutrients1Click(Sender: TObject);
  158.     procedure ShowRumenFunctions1Click(Sender: TObject);
  159.     procedure ShowMinerals1Click(Sender: TObject);
  160.     procedure Currency1Click(Sender: TObject);
  161.  
  162.   private
  163.     procedure MoveIngredient(FromIng,ToIng: Integer);
  164.     procedure SetUpDBFeedLabels;
  165.     procedure SetUpDBFeedPrices;
  166.     procedure AddPreMix(n,ID: Integer;PreM: TCategory;Total: Single);
  167.     procedure SetUpQuery(n: Integer);
  168.     procedure ReadDBClient(n: Integer);
  169.     procedure SetUpQueryPM(n: Integer);
  170.     procedure ReadDBPreMix(n: Integer);
  171.     procedure WriteIniFile;
  172.     procedure GetMinerals;
  173.  
  174.   public
  175.     function CopyDir(const fromDir, toDir: string): Boolean;
  176.     function MoveDir(const fromDir, toDir: string): Boolean;
  177.     function HH(Command: Word; Data: Integer;
  178.           var CallHelp: Boolean): Boolean;
  179.     procedure SetRunButtonEnabledStatus(Enabled: boolean);
  180.     procedure GetFeedOrder(Category,Name,AmountDiet1,AmountDiet2,
  181.                AmountDiet3,AmountDiet4,AmountDiet5: String;FeedNo: Integer;
  182.                var p: Integer);
  183.     procedure IfDietTrue(WeekOfLactation: Integer;{var ProteinLoss,BodyProteinGain,
  184.                             LostProtein,BodyProteinLoss: Single;} Lignin,MatProtein: Single);
  185.     procedure EnDecryptFile(Path: String);
  186.     procedure DisableToolbarOutputButtons;
  187.     procedure ReadFileMinerals;
  188.     procedure ReadFeedPrice;
  189. //    procedure AddFileToDatabase(AName: String);
  190.     function GetDocuments: string;
  191.     function GetProgramFiles: string;
  192.     function GetProfile: string;
  193.     procedure AreTheyChecked(var NotChecked: TNonChecked);
  194.     procedure SeeWhatChecked(var n,m: Integer);
  195.     procedure SeeWhatCheckedPreMix(var n: Integer);
  196. //    procedure AddToClient(Category,Name: String;FeedNo,TMRorPreMix: Integer);
  197. //    procedure AddToPreMix(Name: String;NewPreMixbcp: MakePreMix;TotalPreMixAmount: Single);
  198.     procedure InitializeDBandTables;
  199.     procedure SetUpDBMasterFeeds;
  200.     procedure SetUpDBClientFeeds;
  201.     procedure SetUpDBPreMixes;
  202.     procedure SetUpDBFormulation;
  203.     procedure SetUpDBFarmer;
  204.     procedure SetUpDBResults;
  205.     procedure DateToRestrictCDB;
  206.     function EncryptStr(const S :WideString; Key: Word): String;
  207.     function IsHex(S: String): Boolean;
  208.     function DecryptStr(const S: String; Key: Word): String;
  209.   end;
  210.  
  211. var
  212.  Main: TMain;
  213. ptrFeedInfo: PFeedsRecord;
  214. ptrAnimal: PAnimal;
  215.  
  216.  WCurr: TWC;
  217.  
  218. implementation
  219.  
  220. uses
  221.   SingleForm, ResultsForm, {Cowform,} Outform, {NewFeed,}{ FILicenceInt,} TMR_Conc,
  222.   ChLanguage, AddFood, Protein, Energy, OptionsUsed,  Intro, PrintWhat,
  223.   PDFForm, PDFReports,{ MonthlyLicence,} Blend, AboutUnit, FeedDelete,{ConsultantsReport,}
  224.   shlobj, PreMixDelete, NewClient, ForageCalculator,SetPMName,
  225.   ActiveFibreWarning,MGPcode, Analyse_BCP, ChangeRatesPpn,SetUpDB,Vcl.OleAuto,
  226.   SavingfilestoDB, System.Generics.Collections, System.Generics.Defaults, WhatIf,
  227.   Adminstrator, FeedMill2Solver, Adjust_fNDF, pH6plusFC, RestrictDB, CurrencySelector;
  228.  
  229.  
  230. {$R *.DFM}
  231.  
  232.  
  233. const
  234.   HH_DISPLAY_TOPIC        = $0000;
  235.   HH_DISPLAY_TOC          = $0001;
  236.   HH_CLOSE_ALL            = $0012;
  237.  
  238. var
  239. fsysGrazing,{BackUp,}UpdateYesNo,DifferentHD,RunpH6,SavingData: Boolean;
  240. moptSingle,moptOptim,NewClients,NewFarmers,NewMaster,NewMineral,NewBlends: Boolean;
  241. ProteinLoss,BodyProteinGain,LostProtein,BodyProteinLoss,BdyWt,DMIDiet1,AccessServer: Single;
  242. BeefOrCow: String;
  243. HardDriveNo: Int64;
  244. DBMasterFeedsHigh,DBClientFeedsHigh,DBPreMixFeedsHigh,DBFormulationHigh,
  245. DBFarmerHigh,DBResultsHigh: Integer;
  246.  
  247.  
  248. procedure TMain.FormCreate(Sender: TObject);
  249. var
  250. t,n,LowFormulation,LowFormNo,IndexPosn,DaysToGo,i: Integer;
  251. IniFile: TIniFile;
  252. //ProgressBarStyle: Integer;
  253. ex: Boolean;
  254. Year,Day,Month,YearDS,MonthDS,DayDS: Word;
  255. RDB: String;
  256. EDDateStarted: TDateTime;
  257. Header,NewLine: String;
  258. SupS: TextFile;
  259.  
  260. begin
  261. //put this in to force '.' rather than ','!
  262. FormatSettings.DecimalSeparator:='.';
  263. FormatSettings.DateSeparator:='/';
  264. Main.Top:=1;
  265. //ScaleControls((Screen.Width*100)DIV 1260,100);
  266. FullServerDB:=True; DBConnected:=False;  RunpH6:=True;
  267. Beef:=False;
  268. ex:=False; OneDrive:=True;
  269.  
  270. //Beef:=True;
  271. //MyDocumentsPath is a string that is set by GetDocuments function + ...
  272. MyDocumentsPath:=GetDocuments+'\pH6+ Models';
  273. if Beef then
  274.  begin
  275.  BeefOrCow:='pH6+ Beef';
  276.  DatabaseDirectory:=MyDocumentsPath+'\pH6+ Beef\Database';
  277.  ClientDirectory:=MyDocumentsPath+'\pH6+ Beef\Client';
  278.  end
  279. else
  280.  begin
  281.  BeefOrCow:='pH6+ Milk';
  282.  DatabaseDirectory:=MyDocumentsPath+'\pH6+ Milk\Database';
  283.  ClientDirectory:=MyDocumentsPath+'\pH6+ Milk\Client';
  284.  BatchModePath:=MyDocumentsPath+'\pH6+ Milk\Batch Data Input';
  285.  end;
  286.  
  287. //See if FirstChoice.txt exists which must mean that this is first time
  288. //Check to see if FirstChoice.txt is in GetDocuments directory because if so, it has been loaded already.
  289. if FileExists(DatabaseDirectory+'\FirstChoice.txt') then
  290.  begin
  291.  if FileExists(GetDocuments+'\log_pH6+.ph6') then
  292.   begin
  293.   FirstChoice:=False;
  294.   if FileExists(GetDocuments+'\reg_pH6+.ph6') then
  295.    CopyFile(PWideChar(GetDocuments+'\reg_pH6+.ph6'),PWideChar(DatabaseDirectory+'\pH6+ Milk CD.ini'),False);
  296.   end
  297.  else
  298.   FirstChoice:=True;
  299.  end
  300. else
  301.  begin
  302.  FirstChoice:=False;
  303.  end;
  304. //FirstChoice:=True;
  305. {if OneDrive then
  306.  begin
  307.  if FileExists(GetProfile+'\OneDrive\pH6+\Database\DBFarmer.ph6') then
  308.   CopyFile(PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBFarmer.ph6'),PWideChar(DatabaseDirectory+'\DBFarmer.ph6'),False);
  309.  if FileExists(GetProfile+'\OneDrive\pH6+\Database\DBFormulation.ph6') then
  310.   CopyFile(PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBFormulation.ph6'),PWideChar(DatabaseDirectory+'\DBFormulation.ph6'),False);
  311.  if FileExists(GetProfile+'\OneDrive\pH6+\Database\DBMasterFeeds.ph6') then
  312.   CopyFile(PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBMasterFeeds.ph6'),PWideChar(DatabaseDirectory+'\DBMasterFeeds.ph6'),False);
  313.  if FileExists(GetProfile+'\OneDrive\pH6+\Database\DBPreMixes.ph6') then
  314.   CopyFile(PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBPreMixes.ph6'),PWideChar(DatabaseDirectory+'\DBPreMixes.ph6'),False);
  315.  if FileExists(GetProfile+'\OneDrive\pH6+\Database\DBClientFeeds.ph6') then
  316.   CopyFile(PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBClientFeeds.ph6'),PWideChar(DatabaseDirectory+'\DBClientFeeds.ph6'),False);
  317.  if FileExists(GetProfile+'\OneDrive\pH6+\Database\DBResults.ph6') then
  318.   CopyFile(PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBResults.ph6'),PWideChar(DatabaseDirectory+'\DBResults.ph6'),False);
  319.  if FileExists(GetProfile+'\OneDrive\pH6+\Database\DBFeedPrices.ph6') then
  320.   CopyFile(PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBFeedPrices.ph6'),PWideChar(DatabaseDirectory+'\DBFeedPrices.ph6'),False);
  321.  if FileExists(GetProfile+'\OneDrive\pH6+\Database\'+BeefOrCow+' CD.ini') then
  322.   CopyFile(PWideChar(GetProfile+'\OneDrive\pH6+\Database\'+BeefOrCow+' CD.ini'),PWideChar(DatabaseDirectory+'\'+BeefOrCow+' CD.ini'),False);
  323.  end;     }
  324.  
  325. //have an ini file to remember certain things
  326. EnDeCryptFile(DatabaseDirectory+'\'+BeefOrCow+' CD.ini');
  327. IniFile := TIniFile.Create(DatabaseDirectory+'\'+BeefOrCow+' CD.ini');
  328. LangID:=IniFile.ReadInteger('Language','LangID',1);
  329. kgToOther:=IniFile.ReadFloat('Language','kgToOther',1);
  330. MJToOther:=IniFile.ReadFloat('Language','MJToOther',1);
  331. BatchMode:=IniFile.ReadBool('Maintenance','Batch',BatchMode);
  332. //Beef:=IniFile.ReadBool('Maintenance','Beef',Beef);
  333. //Sheep:=IniFile.ReadBool('Maintenance','Sheep',Sheep);
  334. ShowAFFile:=IniFile.ReadBool('Maintenance','ShowAFFile',True);
  335. MasterFeedsHigh:=IniFile.ReadInteger('Maintenance','MasterFeedsHigh',132);
  336. ClientFeedsHigh:=IniFile.ReadInteger('Maintenance','ClientFeedsHigh',0);
  337. PreMixFeedsHigh:=IniFile.ReadInteger('Maintenance','PreMixFeedsHigh',0);
  338. FarmerHigh:=IniFile.ReadInteger('Maintenance','FarmerHigh',0);
  339. FormulationHigh:=IniFile.ReadInteger('Maintenance','FormulationHigh',0);
  340. ResultsHigh:=IniFile.ReadInteger('Maintenance','ResultsHigh',0);
  341. DBResultsChange:=IniFile.ReadBool('Maintenance','DBResultsChange',False);
  342. DBNotConnected:=IniFile.ReadInteger('Maintenance','DBNotConnected',0);
  343. DateLastUsed:=IniFile.ReadFloat('Maintenance','DateLastUsed',0);
  344. User:=IniFile.ReadString('Maintenance','User','-1');
  345. Password:=IniFile.ReadString('Maintenance','Password','-1');
  346. User_Name:=IniFile.ReadString('Maintenance','UserName','-1');
  347. PW:=IniFile.ReadString('Maintenance','PW','-1');
  348. ProgramCrashed:=IniFile.ReadBool('Maintenance','ProgramCrashed',False);
  349. IniFile.WriteBool('Maintenance','ProgramCrashed',True);
  350. OldClientFeedsHigh:=IniFile.ReadInteger('Maintenance','OldClientFeedsHigh',-1);
  351. OldMasterFeedsHigh:=IniFile.ReadInteger('Maintenance','OldMasterFeedsHigh',-1);
  352. OldPreMixFeedsHigh:=IniFile.ReadInteger('Maintenance','OldPreMixFeedsHigh',-1);
  353. OldFormulationHigh:=IniFile.ReadInteger('Maintenance','OldFormulationHigh',-1);
  354. OldResultsHigh:=IniFile.ReadInteger('Maintenance','OldResultsHigh',-1);
  355. OldFarmerHigh:=IniFile.ReadInteger('Maintenance','OldFarmerHigh',-1);
  356. ForagefNDFfactor:=IniFile.ReadFloat('Maintenance','ForagefNDFfactor',1);
  357. MineralsHigh:=IniFile.ReadInteger('Maintenance','MineralsHigh',6);
  358. DateStarted:=IniFile.ReadString('Maintenance','DateStarted','20-3-2011');
  359. DateChosenToRestrictDB:=IniFile.ReadString('Maintenance','DateChosenToRestrictDB','20-3-2011');
  360. DifferentHDNo:=IniFile.ReadInteger('Maintenance','DifferentHDNo',1);
  361. HighFormulationPos:=IniFile.ReadInteger('Maintenance','HighFormulationPos',0);
  362. HighFormulationNeg:=IniFile.ReadInteger('Maintenance','HighFormulationNeg',-5);
  363. HighResultsPos:=IniFile.ReadInteger('Maintenance','HighResultsPos',0);
  364. HighResultsNeg:=IniFile.ReadInteger('Maintenance','HighResultsNeg',-5);
  365. HighClientNeg:=IniFile.ReadInteger('Maintenance','HighClientNeg',-10);
  366. DateChosenToRestrictDBPM:=IniFile.ReadString('Maintenance','DateChosenToRestrictDBPM','20-3-2011');
  367. HighPreMixesPos:=IniFile.ReadInteger('Maintenance','HighPreMixesPos',0);
  368. HighPreMixesNeg:=IniFile.ReadInteger('Maintenance','HighPreMixesNeg',-10);
  369. YearChosenToRestrictDBFarmer:=IniFile.ReadInteger('Maintenance','YearChosenToRestrictDBFarmer',2011);
  370. AccessServer:=IniFile.ReadFloat('Maintenance','AccessServer',Now);
  371. WCCountry:=IniFile.ReadString('Maintenance','WCCountry','United Kingdom');
  372. WCCurrency:=IniFile.ReadString('Maintenance','WCCurrency','British pound');
  373. WCAbbrev:=IniFile.ReadString('Maintenance','WCAbbrev','£');
  374. WCISO:=IniFile.ReadString('Maintenance','WCISO','GBP');
  375. WCCent:=IniFile.ReadString('Maintenance','WCCent','Penny');
  376. WCFraction:=IniFile.ReadInteger('Maintenance','WCFraction',100);
  377. IniFile.Free;
  378. EnDeCryptFile(DatabaseDirectory+'\'+BeefOrCow+' CD.ini');
  379. //UserName:='db2admin';//'ph6user';//'db2admin';//'ph6user1';
  380. //PW:='pHs1xplus';//'pHs1xuseR';//'pHs1xplus';//'pHs1xuseR1';
  381. if (LangID<1) or (LangID>3) then LangID:=1;
  382. if kgToOther=0 then kgToOther:=1;
  383. if MJToOther=0 then MJToOther:=1;
  384. //Password:='barbie45';
  385. //if User='-1' then FullServerDB:=False;
  386. if MineralsHigh<7 then MineralsHigh:=6;
  387. if FarmerHigh=0 then FarmerHigh:=1;
  388.  
  389. if AccessServer<Now-30 then
  390.  begin
  391.  if AccessServer<Now-60 then
  392.   begin
  393.   ShowMessage('pH6+ Dairy will close down.'+#13#10+
  394.                'You haven''t accessed the server for 60 days.'+#13#10+
  395.                'Please contact [email protected] for more information');
  396.   Application.Terminate;
  397.   end
  398.  else
  399.   begin
  400.   DaysToGo:=60-Round(Now-AccessServer);
  401.   ShowMessage('You must access the server to check on certain things.'+#13#10+ #13#10+
  402.                'pH6+ Dairy will not run after 60 days of non-access.' +#13#10+ #13#10+
  403.                'You have '+IntToStr(DaysToGo)+' days to go!'+#13#10+ #13#10+
  404.                'Please contact [email protected] for more information');
  405.   end;
  406.  end;
  407.  
  408. if Beef then
  409.  Main.Caption:='pH6+ Beef by pH6+ Ltd'
  410. else if Sheep then
  411.  Main.Caption:='pH6+ Sheep by pH6+ Ltd'
  412. else
  413.  Main.Caption:='pH6+ Milk by pH6+ Ltd';
  414. SFV:=False;
  415. //SFV:=True;
  416. SUL:=False;
  417. //SUL:=True;
  418. MUL:=True; SingleAutoSolve:=False;
  419. //MUL:=False; SingleAutoSolve:=False;
  420. BatchMode:=False;
  421. WLtoSR:=False;
  422. Analysebcp1.Visible:=False;
  423. Zaoying:=False;
  424.  Quit1.Visible:=False;
  425.  Optimize1.Visible:=False;
  426. if User_Name='db2admin' then
  427.  begin
  428.  Admin1.Visible:=True;
  429.  end
  430. else
  431.  begin
  432.  Admin1.Visible:=False;
  433.  end;
  434. Administrator:=False; DietTrue:=False;
  435. ForageCalc:=False; ResultsSingleCow:=False; NewForageName:=''; UpdateYesNo:=False;
  436. NotAlkapHer:=True; {Bicarbonate7_74:=True;} AutoSolveName:=False;
  437. BeefCorrection:=True; LagTimeParlour:=false; ChopLength:=True; LongForage:=False;
  438. rFeedInfo.SwardLength:=5;
  439. rFeedInfo.MilkPrice:=28;
  440. rFeedInfo.RC1:=SolubleRate;//0.325;//0.45;
  441. SugarHighRate:=True;
  442. EncryptDatabase:=True;
  443. pH6:=False;
  444. OpenIt:=False;
  445. OpenIt1:=False;
  446. BeenOpen:=False;
  447. version1_8:=True;
  448. PreMixParlourNo:=1;
  449. RoboticHour[1]:=[3,11,15];
  450. rFeedInfo.ParlourFeed:=nil;
  451. PMParlourNameOfTable:=nil;
  452. PMParlourFeedName:=nil;
  453. PMParlourAmount:=nil;
  454. SetLength(rFeedInfo.ParlourFeed,PreMixParlourNo);
  455. SetLength(PMParlourNameOfTable,PreMixParlourNo);
  456. SetLength(PMParlourFeedName,PreMixParlourNo);
  457. SetLength(PMParlourAmount,PreMixParlourNo);
  458. PMParlourAmount[0]:=100;
  459. TMRStarted:=False;
  460. MicrobesAcidosis:=True;
  461. OpenPath:=DatabaseDirectory;
  462. ConsultantPhoneNo:=''; ConsultantName:='';
  463. NewClients:=False; NewFarmers:=False;
  464. if not FirstChoice then
  465.  begin
  466.  try
  467.  InitializeDBandTables;
  468.  except
  469.  on E: EFDDBEngineException do
  470.   begin
  471.   if E.Kind=ekServerGone then
  472.    begin
  473.    DBConnected:=False;
  474.    FDConnection1.Connected:=False;
  475.    SetUpDBMasterFeeds;
  476.    SetUpDBClientFeeds;
  477.    SetUpDBPreMixes;
  478.    SetUpDBFarmer;
  479.    SetUpDBFormulation;
  480.    SetUpDBResults;
  481.    SetUpDBFeedPrices;
  482.    end;
  483.   end;
  484.  end;
  485.  end;
  486. FDConnection1.Connected:=False;
  487.  
  488. if (DateStarted='20-3-2011') and (DBConnected) then
  489.  begin
  490.  LowFormulation:=DBFormulation[0].ID;
  491.  LowFormNo:=0;
  492.  for n := 1 to Length(DBFormulation)-1 do
  493.   begin
  494.   if DBFormulation[n].ID<LowFormulation then
  495.    begin
  496.    LowFormNo:=n;
  497.    end;
  498.   end;
  499.  SysUtils.DecodeDate(DBFormulation[LowFormNo].DietInfo,Year,Month,Day);
  500.  DateStarted:=IntToStr(Day)+'-'+IntToStr(Month)+'-'+IntToStr(Year);
  501.  DateChosenToRestrictDB:=DateStarted;
  502.  end;
  503.  
  504. RDB:=DateStarted;
  505. IndexPosn:=LastDelimiter('-',RDB);
  506. YearDS:=StrToInt(Copy(RDB,IndexPosn+1,Length(RDB)-IndexPosn));
  507. Delete(RDB,IndexPosn,Length(RDB)-IndexPosn+1);
  508. IndexPosn:=LastDelimiter('-',RDB);
  509. MonthDS:=StrToInt(Copy(RDB,IndexPosn+1,Length(RDB)-IndexPosn));
  510. Delete(RDB,IndexPosn,Length(RDB)-IndexPosn+1);
  511. DayDS:=StrToInt(RDB);
  512. EDDateStarted:=EncodeDate(YearDS,MonthDS,DayDS);
  513.  
  514. if EDDateStarted>Now-547 then
  515.  RestrictDB1.Enabled:=False;
  516.  
  517. SetUpDBFeedLabels;
  518. if DBConnected then
  519.  StatusBar1.SimpleText:='Connected'
  520. else
  521.  begin
  522.  StatusBar1.SimpleText:='NOT Connected';
  523.  FromDatabase1.Enabled:=False;
  524.  end;
  525. if DBConnected then
  526.  FDConnection1.Connected:=False;
  527.  
  528. EnDeCryptFile(DatabaseDirectory+'\Stored\DBWC.ph6');
  529. Memo1.Lines.LoadFromFile(DatabaseDirectory+'\Stored\DBWC.ph6');
  530. EnDeCryptFile(DatabaseDirectory+'\Stored\DBWC.ph6');
  531. for i := 0 to Memo1.Lines.Count-1 do
  532.  begin
  533.  NewLine := Memo1.Lines.Strings[i]; // or Line := Memo1.Lines[i];
  534.  IndexPosn:=LastDelimiter(',',NewLine);
  535.  WCurr.WC_Fraction[i+1]:=StrToInt(Copy(NewLine,IndexPosn+1,Length(NewLine)-IndexPosn));
  536.  Delete(NewLine,IndexPosn,Length(NewLine)-IndexPosn+1);
  537.  IndexPosn:=LastDelimiter(',',NewLine);
  538.  WCurr.WC_Cent[i+1]:=Copy(NewLine,IndexPosn+1,Length(NewLine)-IndexPosn);
  539.  Delete(NewLine,IndexPosn,Length(NewLine)-IndexPosn+1);
  540.  IndexPosn:=LastDelimiter(',',NewLine);
  541.  WCurr.WC_ISO[i+1]:=Copy(NewLine,IndexPosn+1,Length(NewLine)-IndexPosn);
  542.  Delete(NewLine,IndexPosn,Length(NewLine)-IndexPosn+1);
  543.  IndexPosn:=LastDelimiter(',',NewLine);
  544.  WCurr.WC_Abbrev[i+1] :=(Copy(NewLine,IndexPosn+1,Length(NewLine)-IndexPosn));
  545.  Delete(NewLine,IndexPosn,Length(NewLine)-IndexPosn+1);
  546.  IndexPosn:=LastDelimiter(',',NewLine);
  547.  WCurr.WC_Currency[i+1]:=Copy(NewLine,IndexPosn+1,Length(NewLine)-IndexPosn);
  548.  Delete(NewLine,IndexPosn,Length(NewLine)-IndexPosn+1);
  549.  IndexPosn:=LastDelimiter(',',NewLine);
  550.  WCurr.WC_Country[i+1]:=Copy(NewLine,IndexPosn+1,Length(NewLine)-IndexPosn);
  551.  end;
  552.  
  553. for i := 1 to 225 do
  554.  begin
  555.  if WCurr.WC_Country[i]=WCCountry then
  556.   begin
  557.   WCCurrency:=WCurr.WC_Currency[i];
  558.   WCAbbrev:=WCurr.WC_Abbrev[i];
  559.   WCISO:=WCurr.WC_ISO[i];
  560.   WCCent:=WCurr.WC_Cent[i];
  561.   WCFraction:=WCurr.WC_Fraction[i];
  562.   end;
  563.  end;
  564.  
  565. SolverExists:=False;
  566. SpeedButton8.Enabled:=False;
  567. SpeedButton10.Enabled:=False;
  568. for n:=1 to 5 do
  569.  begin
  570.  GrazingHour[n]:=[];
  571.  FSParlour[n]:=False;
  572.  ParlourHour[n]:=[5,15];
  573.  end;
  574. if Beef then
  575.  begin
  576.  SpeedButton5.Visible:=False;
  577.  end;
  578. JerseyOpt:=1.0;
  579. for t:=1 to 3 do ParlourFeeds[t]:=2;
  580. for t:=1 to 4 do Fixed_MilkConcentrate[t]:=True;
  581. ActiveFibreonProtein:=True;
  582. NoOfMeals:=11;
  583. rFeedInfo.LPBRwithRumination:=True;
  584. rFeedInfo.RatioLongtoTotal:=0.2;
  585. SingleRun:=True; Virgilio:=False;
  586. fsysGrazing:=True; TMRRobotic12:=False;
  587. moptSingle:=True; OldDiet:=False;
  588. moptOptim:=False;
  589. SolverText:='Favorites_Init.txt';
  590. SpeedButton1.Down:=True;
  591. if Sheep then
  592.  begin
  593.  Animal.Weight:=50;
  594.  Animal.PotMilk:=1;
  595.  Animal.Sex:=2;
  596.  Animal.Species:=2;
  597.  Animal.Maturing:=1;
  598.  Animal.MatureWeight:=75;
  599.  InitialiseAnimal('Sheep');
  600.  LactationDay1:=0.7;
  601.  DigitsOut:=2;
  602.  end
  603. else
  604.  begin
  605.  Animal.Weight:=600;
  606.  Animal.PotMilk:=20;
  607.  Animal.Sex:=2;
  608.  Animal.Species:=1;
  609.  Animal.Maturing:=1;
  610.  Animal.MatureWeight:=750;
  611.  InitialiseAnimal('cow');
  612.  LactationDay1:=20;
  613.  DigitsOut:=1;
  614.  end;
  615. if Beef then Animal.Lactating:=False else Animal.Lactating:=True;
  616.  SRMilkYield:=30;
  617.  SRWeek:=12;
  618.  SRMatureWt:=650;
  619.  SRCS:=2.5;
  620.  SRButter:=3.5;
  621.  SRMilkProtein:=3.3;
  622. Animal.Activity:=0;
  623. LactationLength:=301;
  624. Animal.CloseTo:=3;
  625. Animal.FarOff:=Round((282-LactationLength+70)/7)-Animal.CloseTo;
  626. DayNo[4]:=LactationLength+Round((282+70-LactationLength-21)*0.67);
  627. DayNo[5]:=LactationLength+Animal.FarOff*7+14;
  628. WeekToShow:=6;
  629. SpeedButton5.Enabled:=False;
  630. SpeedButton6.Enabled:=False;
  631. SpeedButton7.Enabled:=False;
  632. File1.Caption:=rTranslate.no2;
  633. Open1.Caption:=rTranslate.no10;
  634. SaveAs1.Caption:=rTranslate.no11;
  635. PrinterSetup1.Caption:=rTranslate.no16;
  636. Quit1.Caption:=rTranslate.no15;
  637. Maintenance1.Caption:=rTranslate.no3;
  638. Help1.Caption:=rTranslate.no5;
  639. SpeedButton1.Caption:=rTranslate.no8;
  640. SpeedButton4.Caption:=rTranslate.no7;
  641. if Beef then
  642.  btnRun.Caption:=rTranslate.no9+' pH6+ Beef'
  643. else
  644.  btnRun.Caption:=rTranslate.no9+' pH6+ Milk';
  645. SpeedButton7.Hint:=rTranslate.no11;
  646. SpeedButton5.Caption:=rTranslate.no12;
  647. SpeedButton6.Caption:=rTranslate.no13;
  648. SpeedButton8.Hint:=rTranslate.no14;
  649. SpeedButton3.Caption:=rTranslate.no15;
  650. rFeedInfo.DietToFed[1]:=True;
  651.  rFeedInfo.DietToFed[2]:=False;
  652.  rFeedInfo.DietToFed[3]:=False;
  653. rFeedInfo.DietToFed[4]:=False;
  654. rFeedInfo.DietToFed[5]:=False;
  655. rFeedInfo.DynamicWater:=True;
  656. rFeedInfo.AddFeed:=False;
  657. rFeedInfo.LagTime:=True;
  658. rFeedInfo.Long:=True;
  659. rFeedInfo.Pectins:=True;
  660. DMAmount[1]:='';
  661. for n:=1 to 5 do
  662.  FSGrazingAll[n]:=False;
  663. rFeedInfo.MY305d1[1,1]:=0.76842;
  664. rFeedInfo.MY305d1[2,1]:=0.76842;//1;
  665. rFeedInfo.MY305d1[1,2]:=0.9399;//1.2232;
  666. rFeedInfo.MY305d1[2,2]:=0.9399;//1.2232;
  667. rFeedInfo.MY305d1[1,3]:=1;//1.3014;
  668. rFeedInfo.MY305d1[2,3]:=1;//1.3014;
  669. rFeedInfo.MY305d[3]:=8000;
  670. rFeedInfo.MY305d[1]:=Round(rFeedInfo.MY305d[3]*{/}rFeedInfo.MY305d1[1,1{3}]);
  671. rFeedInfo.MY305d[2]:=Round(rFeedInfo.MY305d[3]*rFeedInfo.MY305d1[1,2]);
  672. ReadFileMinerals;
  673. StartFS:=True;
  674. NewType:=False;
  675. rFeedInfo.ACHOintoWSCsNDF:=True;
  676. rFeedInfo.iParlour:=0;
  677. rFeedInfo.iGrazing:=0;
  678. rFeedInfo.iRobotic:=0;
  679. rFeedInfo.iLiquid:=0;
  680. rFeedInfo.PreMix:=0;
  681. rFeedInfo.iNonPMFeeds:=0;
  682. ParlourNDF:=0;
  683. ParlourOil:=0;
  684. IMustSave:=False;
  685. Yeast:=False;
  686. LargeBull:=1100; LargeSteer:=990; LargeHeifer:=900; LargeHS:=945;
  687. MediumBull:=950; MediumSteer:=880; MediumHeifer:=800; MediumHS:=840;
  688. SmallBull:=780; SmallSteer:=715; SmallHeifer:=655; SmallHS:=680;
  689. PBNa[1]:=2.5;PBNa[2]:=3;PBNa[3]:=7;   //3.5
  690. PBK[1]:=12.5;PBK[2]:=17.5;PBK[3]:=25;
  691. PBP[1]:=3.8;PBP[2]:=4.2;PBP[3]:=4.6;
  692. PBCa[1]:=PBP[1]*1.75;PBCa[2]:=PBP[2]*1.75;PBCa[3]:=PBP[3]*2;
  693. PBCl[1]:=6;PBCl[2]:=6.5;PBCl[3]:=9;
  694. PBS[1]:=2;PBS[2]:=25;PBS[3]:=30;
  695. PBMg[1]:=PBK[1]*0.2;PBMg[2]:=PBK[2]*0.2;PBMg[3]:=PBK[3]*0.25;
  696. PBCu[1]:=12;PBCu[2]:=20;PBCu[3]:=40;
  697. PBSe[1]:=0.3;PBSe[2]:=0.4;PBSe[3]:=0.5;
  698. PBZn[1]:=60;PBZn[2]:=100;PBZn[3]:=150;
  699. PBFe[1]:=150;PBFe[2]:=450;PBFe[3]:=750;
  700. PBMo[1]:=0;PBMo[2]:=1.5;PBMo[3]:=2.5;
  701. AutoCreatePreMix:=True; ParlourPreMix:=False;
  702. ModifyRates1.Visible:=False;
  703. NotRunYet:=False;
  704. RestSalivaPpn:=1.25; ParticlePassagePpn:=1; LargeParticleBR:=1; MaxRuminationFactor:=1;
  705. LargeParticleIntakePpn:=1;
  706. TCM:=False; version1_01_16:=True;
  707. PreMixesDelDB:=False; SavingResults:=False; SavingData:=False;
  708. ClientDelDB:=False; AdjustfNDFClientFeed:=0;
  709. {AssignFile(SupS,'Minerals.mrq');
  710. Rewrite(SupS);
  711. Writeln(SupS,'Na ReqL ReqNL TolL TolNL');
  712. Header:='2.5'+','+'0.8'+','+'15.7'+','+'35.4'+',';
  713. Write(SupS,Header);
  714. Writeln(SupS,'');
  715. Writeln(SupS,'K');
  716. Header:='10'+','+'6.5'+','+'30'+','+'30'+',';
  717. Write(SupS,Header);
  718. Writeln(SupS,'');
  719. Writeln(SupS,'Ca');
  720. Header:='7'+','+'5'+','+'20'+','+'20'+',';
  721. Write(SupS,Header);
  722. Writeln(SupS,'');
  723. Writeln(SupS,'Mg');
  724. Header:='2.4'+','+'1.8'+','+'5'+','+'5'+',';
  725. Write(SupS,Header);
  726. Writeln(SupS,'');
  727. Writeln(SupS,'Cl');
  728. Header:='3.25'+','+'2'+','+'24.3'+','+'54.6'+',';
  729. Write(SupS,Header);
  730. Writeln(SupS,'');
  731. Writeln(SupS,'P');
  732. Header:='3.75'+','+'2'+','+'10'+','+'10'+',';
  733. Write(SupS,Header);
  734. Writeln(SupS,'');
  735. Writeln(SupS,'S');
  736. Header:='2'+','+'1.5'+','+'3.5'+','+'3.5'+',';
  737. Write(SupS,Header);
  738. Writeln(SupS,'');
  739. Writeln(SupS,'Cu');
  740. Header:='15'+','+'10'+','+'100'+','+'100'+',';
  741. Write(SupS,Header);
  742. Writeln(SupS,'');
  743. Writeln(SupS,'Se');
  744. Header:='0.3'+','+'0.15'+','+'2'+','+'2'+',';
  745. Write(SupS,Header);
  746. Writeln(SupS,'');
  747. Writeln(SupS,'Zn');
  748. Header:='60'+','+'40'+','+'500'+','+'500'+',';
  749. Write(SupS,Header);
  750. Writeln(SupS,'');
  751. Writeln(SupS,'Mn');
  752. Header:='80'+','+'80'+','+'1000'+','+'1000'+',';
  753. Write(SupS,Header);
  754. Writeln(SupS,'');
  755. Writeln(SupS,'Mo');
  756. Header:='1.75'+','+'1.75'+','+'10'+','+'10'+',';
  757. Write(SupS,Header);
  758. Writeln(SupS,'');
  759. CloseFile(SupS); }
  760. end;
  761.  
  762. procedure TMain.SetUpDBFarmer;
  763. var
  764. n: Integer;
  765. DecryptTelephone: Bool;
  766. //Value: Bool;
  767.  
  768. begin
  769. //DBNotConnected:=0;
  770. if (DBConnected) and (DBNotConnected=0) then
  771.  begin
  772.  if (FileExists(DatabaseDirectory+'\DBFarmer.ph6')) and (not DifferentHD) and
  773.   {((n=FarmerHigh) or }(NewFarmers=False) and (Administrator=False) and (UpdateYesNo=False) then
  774.   begin
  775.   n:=FarmerHigh;
  776.   DBFarmer:=nil;
  777.   SetLength(DBFarmer,n);
  778.   EnDeCryptFile(DatabaseDirectory+'\DBFarmer.ph6');
  779.   OpenFarmer(n);
  780.   EnDeCryptFile(DatabaseDirectory+'\DBFarmer.ph6');
  781.   end
  782.  else
  783.   begin
  784.   with FDQuery1 do
  785.    begin
  786.    DisableControls;
  787.    Close;
  788.    SQL.Clear;
  789.    SQL.Add('SELECT *');
  790.    SQL.Add('FROM  MasterTable ');
  791.    SQL.Add('WHERE  Consultant =:apptype');
  792.    SQL.Add('AND  YearStarted  >= :apptype1');
  793.    Params[0].DataType:=ftInteger;
  794.    Params[0].Value:=Consultant;
  795.    Params[1].DataType:=ftInteger;
  796.    Params[1].Value:=YearChosenToRestrictDBFarmer;
  797.    Open;
  798.    EnableControls;
  799.    end;
  800.   FarmerHigh:=FDQuery1.RecordCount;
  801.   DBFarmer:=nil;
  802.   SetLength(DBFarmer,FarmerHigh);
  803.   FDQuery1.First;
  804.   n:=0;
  805.   while not FDQuery1.Eof do
  806.    begin
  807.    DecryptTelephone:=False;
  808.    DBFarmer[n].Code:=FDQuery1.FieldByName('FarmerDetails').AsString;
  809.    DBFarmer[n].DietID:=FDQuery1.FieldByName('ID').AsInteger;
  810.    if (IsHex(FDQuery1.FieldByName('Name').AsString)) and (FDQuery1.FieldByName('Name').AsString<>'') then
  811.     begin
  812.     DBFarmer[n].Name:=DecryptStr(FDQuery1.FieldByName('Name').AsString,223);
  813.     DecryptTelephone:=True;
  814.     end
  815.    else
  816.     DBFarmer[n].Name:=FDQuery1.FieldByName('Name').AsString;
  817.    if (IsHex(FDQuery1.FieldByName('Address1').AsString)) and (FDQuery1.FieldByName('Address1').AsString<>'') then
  818.     DBFarmer[n].Add1:=DecryptStr(FDQuery1.FieldByName('Address1').AsString,223)
  819.    else
  820.     DBFarmer[n].Add1:=FDQuery1.FieldByName('Address1').AsString;
  821.    if (IsHex(FDQuery1.FieldByName('Address2').AsString)) and (FDQuery1.FieldByName('Address2').AsString<>'') then
  822.     DBFarmer[n].Add2:=DecryptStr(FDQuery1.FieldByName('Address2').AsString,223)
  823.    else
  824.     DBFarmer[n].Add2:=FDQuery1.FieldByName('Address2').AsString;
  825.    if (IsHex(FDQuery1.FieldByName('Address3').AsString)) and (FDQuery1.FieldByName('Address3').AsString<>'') then
  826.     DBFarmer[n].Add3:=DecryptStr(FDQuery1.FieldByName('Address3').AsString,223)
  827.    else
  828.     DBFarmer[n].Add3:=FDQuery1.FieldByName('Address3').AsString;
  829.    if (IsHex(FDQuery1.FieldByName('Postcode').AsString)) and (FDQuery1.FieldByName('Postcode').AsString<>'') then
  830.     DBFarmer[n].PC:=DecryptStr(FDQuery1.FieldByName('Postcode').AsString,223)
  831.    else
  832.     DBFarmer[n].PC:=FDQuery1.FieldByName('Postcode').AsString;
  833.    if (DecryptTelephone) and (FDQuery1.FieldByName('Telephone').AsString<>'') then
  834.     DBFarmer[n].Tel:=DecryptStr(FDQuery1.FieldByName('Telephone').AsString,223)
  835.    else
  836.     DBFarmer[n].Tel:=FDQuery1.FieldByName('Telephone').AsString;
  837.    if (IsHex(FDQuery1.FieldByName('Email').AsString)) and (FDQuery1.FieldByName('Email').AsString<>'') then
  838.     DBFarmer[n].Email:=DecryptStr(FDQuery1.FieldByName('Email').AsString,223)
  839.    else
  840.     DBFarmer[n].Email:=FDQuery1.FieldByName('Email').AsString;
  841.  
  842.  
  843.    {Value:=IsHex(FDQuery1.FieldByName('Name').AsString);
  844.    if FDQuery1.FieldByName('Name').AsString='' then Value:=False;
  845.    if Value then
  846.     begin
  847.     DBFarmer[n].Name:=DecryptStr(FDQuery1.FieldByName('Name').AsString,223);
  848.     DBFarmer[n].Add1:=DecryptStr(FDQuery1.FieldByName('Address1').AsString,223);
  849.     DBFarmer[n].Add2:=DecryptStr(FDQuery1.FieldByName('Address2').AsString,223);
  850.     DBFarmer[n].Add3:=DecryptStr(FDQuery1.FieldByName('Address3').AsString,223);
  851.     DBFarmer[n].PC:=DecryptStr(FDQuery1.FieldByName('Postcode').AsString,223);
  852.     DBFarmer[n].Tel:=DecryptStr(FDQuery1.FieldByName('Telephone').AsString,223);
  853.     DBFarmer[n].Email:=DecryptStr(FDQuery1.FieldByName('Email').AsString,223);
  854.     end
  855.    else
  856.     begin
  857.     DBFarmer[n].Name:=FDQuery1.FieldByName('Name').AsString;
  858.     DBFarmer[n].Add1:=FDQuery1.FieldByName('Address1').AsString;
  859.     DBFarmer[n].Add2:=FDQuery1.FieldByName('Address2').AsString;
  860.     DBFarmer[n].Add3:=FDQuery1.FieldByName('Address3').AsString;
  861.     DBFarmer[n].PC:=FDQuery1.FieldByName('Postcode').AsString;
  862.     DBFarmer[n].Tel:=FDQuery1.FieldByName('Telephone').AsString;
  863.     DBFarmer[n].Email:=FDQuery1.FieldByName('Email').AsString;
  864.     end;}
  865.    DBFarmer[n].New:=0;
  866.    inc(n);
  867.    FDQuery1.Next;
  868.    end;
  869.   FDQuery1.Close;
  870.   end;
  871.  end
  872. else
  873.  begin
  874.  DBFarmer:=nil;
  875.  SetLength(DBFarmer,FarmerHigh);
  876.  EnDeCryptFile(DatabaseDirectory+'\DBFarmer.ph6');
  877.  OpenFarmer(FarmerHigh);
  878.  EnDeCryptFile(DatabaseDirectory+'\DBFarmer.ph6');
  879.  end;
  880. if FirstChoice then Welcome.FormCreate(Self);
  881. FirstChoice:=False;
  882. end;
  883.  
  884.  
  885.  
  886. procedure TMain.SpeedButton6Click(Sender: TObject);
  887. const
  888. DivideBy=1.1;
  889.  
  890. var
  891. TimePoint,MultiplyBy: Integer;
  892. DontShow: Boolean;
  893. SupS: TextFile;
  894. Header: String;
  895. MyRgn: HRGN;
  896.  
  897. begin
  898. DontShow:=False;
  899. if SingleRun then
  900.  begin
  901. // EnlargeOutput:=True;
  902.  if EnlargeOutput then MultiplyBy:=2 else MultiplyBy:=1;
  903.  Results.PageControl1.Visible:=False;
  904.  Results.VertScrollBar.Position:=0;
  905.  Results.HorzScrollBar.Position:=0;
  906.  Results.Panel4.Visible:=True;
  907.  Results.Panel4.Top:=10;
  908.  Results.Panel4.Left:=10;
  909.  Results.Panel4.Width:=Round(MultiplyBy*210/25.4*Results.PixelsPerInch/DivideBy);
  910.  Results.Panel4.Height:=Round(MultiplyBy*297/25.4*Results.PixelsPerInch/DivideBy);
  911.  if EnlargeOutput then
  912.   begin
  913.   if EnlargeGraphs then
  914.    begin
  915.    Results.VertScrollBar.Position:=Round(Results.Panel4.Height*0.32);
  916.    Results.HorzScrollBar.Position:=Round(Results.Panel4.Width*0.75);
  917.    end;
  918.   if EnlargeDiet then
  919.    begin
  920.    Results.VertScrollBar.Position:=Round(Results.Panel4.Height*0.21);
  921.    Results.HorzScrollBar.Position:=0;
  922.    end;
  923.   if EnlargeNutrients then
  924.    begin
  925.    Results.VertScrollBar.Position:=Round(Results.Panel4.Height*0.535);
  926.    Results.HorzScrollBar.Position:=0;
  927.    end;
  928.   if EnlargeMilk then
  929.    begin
  930.    Results.VertScrollBar.Position:=Round(Results.Panel4.Height*0.19);
  931.    Results.HorzScrollBar.Position:=Round(Results.Panel4.Width*0.75);
  932.    end;
  933.   if EnlargeRumen then
  934.    begin
  935.    Results.VertScrollBar.Position:=Round(Results.Panel4.Height*0.66);
  936.    Results.HorzScrollBar.Position:=0;
  937.    end;
  938.   if EnlargeMinerals then
  939.    begin
  940.    Results.VertScrollBar.Position:=Round(Results.Panel4.Height*0.65);
  941.    Results.HorzScrollBar.Position:=Round(Results.Panel4.Width*0.75);
  942.    end;
  943.   end
  944.  else
  945.   begin
  946.   Results.VertScrollBar.Position:=Round(205*Results.PixelsPerInch/96);
  947.   end;
  948.  if Beef then TimePoint:=1
  949.  else
  950.   begin
  951.   if LeftStr(Instant.Edit66.Text,1)='-' then
  952.    TimePoint:=Round(LactationLength/DaysInWeek)+7
  953.                  +StrToInt(Instant.Edit66.Text)
  954.   else
  955.    TimePoint:=StrToInt(Instant.Edit66.Text);
  956.   end;
  957.  if rNutrientsAbsorbed.DMI[SRLactNo,TimePoint-1]=0 then
  958.   begin
  959.   ShowMessage('The rumen pH is too low!'+#10#13+'Try reducing starch and/or increases NDF in the diet.'+#10#13+
  960.               'If CP is too low, try increasing CP');
  961.   DontShow:=True;
  962.   end
  963.  else if (rNutrientsAbsorbed.ParlourDMI[SRLactNo,TimePoint-1]>=
  964.    rNutrientsAbsorbed.DMI[SRLactNo,TimePoint-1]) then
  965.    begin
  966.    ShowMessage('You have put in too much Parlour Feed!'+#10#13+
  967.                'Please reduce the amount fed.'+#10#13+
  968.                'Parlour: '+FloatToStr(rNutrientsAbsorbed.ParlourDMI[SRLactNo,TimePoint-1])+#10#13+
  969.                'DMI: '+FloatToStr(rNutrientsAbsorbed.DMI[SRLactNo,TimePoint-1])+#10#13+
  970.                'SRLactNo: '+IntToStr(SRLactNo)+#10#13+
  971.                'TimePoint: '+IntToStr(TimePoint)+#10#13+
  972.                'Days completed:= '+IntToStr(WhyWontItWork)+#10#13+
  973.                'Intake= '+FloatToStr(WWIW)) ;
  974.    DontShow:=True;
  975.    end
  976.  else
  977.  
  978.  SingleRunOutput(Results.Image4.Canvas,@Feeding,Results.Panel4.Width,
  979.                   Results.Panel4.Height,TimePoint,DivideBy);
  980.  
  981.                   { if FileExists('NeilNDF.txt') then
  982.   begin
  983.   if not DirectoryExists(ClientDirectory+'\ForageNDF') then
  984.    ForceDirectories(ClientDirectory+'\ForageNDF');
  985.   AssignFile(SupS,ClientDirectory+'\ForageNDF\'+Farmer.FD+'-ForageNDF.csv');
  986.   ReWrite(SupS);
  987.   Header:='Forage NDF'+',';
  988.   for TimePoint := 1 to 24 do
  989.    Header:=Header+IntToStr(TimePoint)+',';
  990.   WriteLn(SupS,Header);
  991.   Header:='Total Large Particle Forage NDF'+',';
  992.   for TimePoint := 1 to 24 do
  993.    Header:=Header+FloatToStr(TLongNDFForage[TimePoint])+',';
  994.   WriteLn(SupS,Header);
  995.   Header:='Unfermentable Large Particle Forage NDF'+',';
  996.   for TimePoint := 1 to 24 do
  997.    Header:=Header+FloatToStr(ULongNDFForage[TimePoint])+',';
  998.   WriteLn(SupS,Header);
  999.   Header:='Total Forage NDF'+',';
  1000.   for TimePoint := 1 to 24 do
  1001.    Header:=Header+FloatToStr(TNDFForage[TimePoint])+',';
  1002.   WriteLn(SupS,Header);
  1003.   Header:='Unfermentable Forage NDF'+',';
  1004.   for TimePoint := 1 to 24 do
  1005.    Header:=Header+FloatToStr(UNDFForage[TimePoint])+',';
  1006.   WriteLn(SupS,Header);
  1007.   CloseFile(SupS);
  1008.   end; }
  1009.  end;
  1010.  
  1011. if not DontShow then Results.Show;
  1012. end;
  1013.  
  1014. function TMain.GetDocuments: string;
  1015. var
  1016.    r: Bool;
  1017.    path: array[0..Max_Path] of Char;
  1018.    text: String;
  1019. begin
  1020.    r := ShGetSpecialFolderPath(0, path, CSIDL_PERSONAL , False) ;
  1021.    if LangID=2 then
  1022.     text:='Dossier ''mes documents'' introuve'
  1023.    else
  1024.     text:='Could not find MyDocuments folder location.';
  1025.    if not r then raise Exception.Create(text) ;
  1026.    Result := Path;
  1027. end;
  1028.  
  1029. function TMain.GetProgramFiles: string;
  1030. var
  1031.    r: Bool;
  1032.    path: array[0..Max_Path] of Char;
  1033.    text: String;
  1034. begin
  1035.    r := ShGetSpecialFolderPath(0, path, CSIDL_PROGRAM_FILES , False) ;
  1036.    text:='Could not find Program Files folder location.';
  1037.    if not r then raise Exception.Create(text) ;
  1038.    Result := Path;
  1039. end;
  1040.  
  1041. function TMain.GetProfile: string;
  1042. var
  1043.    r: Bool;
  1044.    path: array[0..Max_Path] of Char;
  1045.    text: String;
  1046. begin
  1047.    r := ShGetSpecialFolderPath(0, path, CSIDL_PROFILE , False) ;
  1048.    text:='Could not find Profile folder location.';
  1049.    if not r then raise Exception.Create(text) ;
  1050.    Result := Path;
  1051. end;
  1052.  
  1053.  
  1054. function HtmlHelp(hwndCaller: HWND;
  1055.   pszFile: PChar; uCommand: UINT;
  1056.   dwData: DWORD): HWND; stdcall;
  1057.   external 'HHCTRL.OCX' name 'HtmlHelpW';
  1058.  
  1059. procedure TMain.SetRunButtonEnabledStatus(Enabled: boolean);
  1060. var
  1061.   ToolbarRunButton: TControl;
  1062. begin
  1063.   ToolbarRunButton := Main.btnRun;
  1064.   if version1_8 then ToolbarRunButton.Enabled := Enabled;
  1065. end;
  1066.  
  1067. procedure TMain.DisableToolbarOutputButtons;
  1068. // Disables the toolbar output buttons (Graph & Table) - these are re-enabled
  1069. // once the toolbar Run button is clicked.
  1070. // The Graph button is TMain.SpeedButton5
  1071. // The Table button is TMain.SpeedButton6
  1072. var
  1073.   ToolbarGraphButton: TSpeedButton;
  1074.   ToolbarTableButton: TSpeedButton;
  1075. begin
  1076.   ToolbarGraphButton := Self.SpeedButton5;
  1077.   ToolbarTableButton := Self.SpeedButton6;
  1078.   if version1_8 then
  1079.    begin
  1080.    ToolbarGraphButton.Enabled := False;
  1081.    ToolbarGraphButton.Down    := False;
  1082.    ToolbarTableButton.Enabled := False;
  1083.    ToolbarTableButton.Down    := False;
  1084.    end;
  1085. end;
  1086.  
  1087. procedure TMain.EnDecryptFile(Path: String);
  1088. var
  1089.   InMS, OutMS: TMemoryStream;
  1090.   cnt: Integer;
  1091.   C: byte;
  1092.  
  1093. begin
  1094.   InMS  := TMemoryStream.Create;
  1095.   OutMS := TMemoryStream.Create;
  1096.   try
  1097.     InMS.LoadFromFile(Path);
  1098.     InMS.Position := 0;
  1099.     for cnt := 0 to InMS.Size - 1 DO
  1100.       begin
  1101.         InMS.Read(C, 1);
  1102.         C := (C xor not (ord(5981 shr cnt)));
  1103.         OutMS.Write(C, 1);
  1104.       end;
  1105.     OutMS.SaveToFile(Path);
  1106.   finally
  1107.     InMS.Free;
  1108.     OutMS.Free;
  1109.   end;
  1110. end;
  1111.  
  1112. procedure TMain.Enlarge1Click(Sender: TObject);
  1113. begin
  1114. //if EnlargeOutput and (EnlargeGraphs or EnlargeDiet
  1115. // or EnlargeMilk or EnlargeNutrients or EnlargeNutrients
  1116. // or EnlargeMinerals) then EnlargeOutput:=False else EnlargeOutput:=True;
  1117. end;
  1118.  
  1119. function TMain.EncryptStr(const S :WideString; Key: Word): String;
  1120. var   i          :Integer;
  1121.       RStr       :RawByteString;
  1122.       RStrB      :TBytes Absolute RStr;
  1123. begin
  1124.   Result:= '';
  1125.   RStr:= UTF8Encode(S);
  1126.   for i := 0 to Length(RStr)-1 do begin
  1127.     RStrB[i] := RStrB[i] xor (Key shr 8);
  1128.     Key := (RStrB[i] + Key) * CKEY1 + CKEY2;
  1129.   end;
  1130.   for i := 0 to Length(RStr)-1 do begin
  1131.     Result:= Result + IntToHex(RStrB[i], 2);
  1132.   end;
  1133. end;
  1134.  
  1135. function TMain.IsHex(S: String): Boolean;
  1136. var
  1137. n: Integer;
  1138.  
  1139. begin
  1140. Result:=True;
  1141.   for n := 1 to length(s) do
  1142.     if not (char(s[n]) in ['0'..'9']) and not (char(s[n]) in ['A'..'F']) then
  1143.     begin
  1144.       Result:=False;
  1145.       exit;
  1146.     end;
  1147. end;
  1148.  
  1149. function TMain.DecryptStr(const S: String; Key: Word): String;
  1150. var   i, tmpKey  :Integer;
  1151.       RStr       :RawByteString;
  1152.       RStrB      :TBytes Absolute RStr;
  1153.       tmpStr     :string;
  1154. begin
  1155.   tmpStr:= UpperCase(S);
  1156.   SetLength(RStr, Length(tmpStr) div 2);
  1157.   i:= 1;
  1158.   try
  1159.     while (i < Length(tmpStr)) do begin
  1160.       RStrB[i div 2]:= StrToInt('$' + tmpStr[i] + tmpStr[i+1]);
  1161.       Inc(i, 2);
  1162.     end;
  1163.   except
  1164.     Result:= '';
  1165.     Exit;
  1166.   end;
  1167.   for i := 0 to Length(RStr)-1 do begin
  1168.     tmpKey:= RStrB[i];
  1169.     RStrB[i] := RStrB[i] xor (Key shr 8);
  1170.     Key := (tmpKey + Key) * CKEY1 + CKEY2;
  1171.   end;
  1172.   Result:= UTF8ToString(RStr);
  1173. end;
  1174.  
  1175. procedure TMain.SetUpQueryPM(n: Integer);
  1176. begin
  1177.   with FDQuery1 do
  1178.    begin
  1179.    DisableControls;
  1180.    Close;
  1181.    SQL.Clear;
  1182.    SQL.Add('SELECT *');
  1183.    SQL.Add('FROM Blends ');     //localhost
  1184.    SQL.Add('WHERE Consultant =:apptype');
  1185. //   if n=1 then
  1186.     SQL.Add('AND  DateAdded  > :DateLastUsed');
  1187.    Params[0].DataType:=ftInteger;
  1188.    Params[0].Value:=Consultant;
  1189. //   if n=1 then
  1190. //    begin
  1191.     Params[1].DataType:=ftInteger;
  1192.     Params[1].Value:=DateIntegerPM;
  1193. //    end;
  1194.    Open;
  1195.    EnableControls;
  1196.    end;
  1197.   FDQuery1.First;
  1198. end;
  1199.  
  1200.  
  1201. procedure TMain.SetUpQuery(n: Integer);
  1202. begin
  1203.   with FDQuery1 do
  1204.    begin
  1205.    DisableControls;
  1206.    Close;
  1207.    SQL.Clear;
  1208.    SQL.Add('SELECT *');
  1209.    SQL.Add('FROM Client ');
  1210.    SQL.Add('WHERE ( Consultant =:apptype)');
  1211.    SQL.Add('AND ( DateAdded >:apptype1');
  1212.    SQL.Add('OR  ID <0)');
  1213.    Params[0].DataType:=ftInteger;
  1214.    Params[0].Value:=Consultant;
  1215.    Params[1].DataType:=ftInteger;
  1216.    Params[1].Value:=DateInteger-60;
  1217.    Open;
  1218.    EnableControls;
  1219.    end;
  1220.   FDQuery1.First;
  1221. end;
  1222.  
  1223. procedure TMain.SetUpDBFormulation;
  1224. var
  1225. n: Integer;
  1226.  
  1227. begin
  1228. //DBNotConnected:=0;
  1229. if (DBConnected) and (DBNotConnected=0) then
  1230.  begin
  1231.  if (FileExists(DatabaseDirectory+'\DBFormulation.ph6')) {and (n=FormulationHigh) }
  1232.   and (Administrator=False) and (UpdateYesNo=False) and (not DifferentHD) then
  1233.   begin
  1234.   n:=FormulationHigh;
  1235.   DBFormulation:=nil;
  1236.   SetLength(DBFormulation,n);
  1237.   EnDeCryptFile(DatabaseDirectory+'\DBFormulation.ph6');
  1238.   OpenFormulation(n);
  1239.   EnDeCryptFile(DatabaseDirectory+'\DBFormulation.ph6');
  1240.   end
  1241.  else
  1242.   begin
  1243.   with FDQuery1 do
  1244.    begin
  1245.    DisableControls;
  1246.    Close;
  1247.    SQL.Clear;
  1248.    SQL.Add('SELECT *');
  1249.    SQL.Add('FROM  Formulation ');
  1250.    SQL.Add('WHERE  Consultant =:apptype');
  1251.    SQL.Add('AND  Started >:apptype1');
  1252.    Params[0].DataType:=ftInteger;
  1253.    Params[0].Value:=Consultant;
  1254.    Params[1].DataType:=ftInteger;
  1255.    Params[1].Value:=DateInteger;
  1256.    Open;
  1257.    EnableControls;
  1258.    end;
  1259.   FDQuery1.First;
  1260.   FormulationHigh:=FDQuery1.RecordCount;
  1261.   DBFormulation:=nil;
  1262.   SetLength(DBFormulation,FormulationHigh);
  1263.   n:=0;
  1264.   while not FDQuery1.Eof do
  1265.    begin
  1266.    DBFormulation[n].ID:=FDQuery1.FieldByName('ID').AsInteger;
  1267.    DBFormulation[n].FarmerDetails:=FDQuery1.FieldByName('FarmerDetails').AsString;
  1268.    DBFormulation[n].FormDate:=FDQuery1.FieldByName('FormDate').AsString;
  1269.    DBFormulation[n].StartDate:=FDQuery1.FieldByName('StartDate').AsString;
  1270.    DBFormulation[n].FinishDate:=FDQuery1.FieldByName('FinishDate').AsString;
  1271.    DBFormulation[n].Nutritionist:=FDQuery1.FieldByName('Nutritionist').AsString;
  1272.    DBFormulation[n].DietInfo:=FDQuery1.FieldByName('Started').AsInteger;
  1273.    DBFormulation[n].NowInt:=Round(DateTimeToModifiedJulianDate(DBFormulation[n].DietInfo)*Thousand);
  1274.    DBFormulation[n].New:=0;
  1275.    inc(n);
  1276.    FDQuery1.Next;
  1277.    end;
  1278.   end;
  1279.  FDQuery1.Close;
  1280.  end
  1281. else
  1282.  begin
  1283.  DBFormulation:=nil;
  1284.  SetLength(DBFormulation,FormulationHigh);
  1285.  EnDeCryptFile(DatabaseDirectory+'\DBFormulation.ph6');
  1286.  OpenFormulation(FormulationHigh);
  1287.  EnDeCryptFile(DatabaseDirectory+'\DBFormulation.ph6');
  1288.  end;
  1289. TArray.Sort<TFormulation>(DBFormulation, TDelegatedComparer<TFormulation>.Construct
  1290.               (function(const Left, Right: TFormulation): Integer
  1291.               begin
  1292.                Result:=TComparer<Integer>.Default.Compare(Left.NowInt,Right.NowInt);
  1293.               end));
  1294. end;
  1295.  
  1296.  
  1297.  
  1298. procedure TMain.SetUpDBResults;
  1299. var
  1300. n: Integer;
  1301.  
  1302. begin
  1303. //DBNotConnected:=0;
  1304. if (DBConnected) and (DBNotConnected=0) then
  1305.  begin
  1306.  if (FileExists(DatabaseDirectory+'\DBResults.ph6')) {and (n=ResultsHigh)} and (not DifferentHD)
  1307.   and (not DBResultsChange) and (Administrator=False) and (UpdateYesNo=False) then
  1308.   begin
  1309.   n:=ResultsHigh;
  1310.   DBResults:=nil;
  1311.   SetLength(DBResults,n);
  1312.  // EnDeCryptFile(DatabaseDirectory+'\DBResults.ph6');
  1313.   OpenResults(n);
  1314.  // EnDeCryptFile(DatabaseDirectory+'\DBResults.ph6');
  1315.   end
  1316.  else
  1317.   begin
  1318.   with FDQuery1 do
  1319.    begin
  1320.    DisableControls;
  1321.    Close;
  1322.    SQL.Clear;
  1323.    SQL.Add('SELECT *');
  1324.    SQL.Add('FROM  Results ');
  1325.    SQL.Add('WHERE  Consultant =:apptype');
  1326.    SQL.Add('AND  Diet  IN (Select  ID  FROM  Formulation  WHERE  Consultant =:apptype AND  Started >:apptype1)');
  1327.    Params[0].DataType:=ftInteger;
  1328.    Params[0].Value:=Consultant;
  1329.    Params[1].DataType:=ftInteger;
  1330.    Params[1].Value:=DateInteger;
  1331.    Open;
  1332.    EnableControls;
  1333.    end;
  1334.   FDQuery1.First;
  1335.   ResultsHigh:=FDQuery1.RecordCount;
  1336.   DBResults:=nil;
  1337.   SetLength(DBResults,ResultsHigh);
  1338.   DBResultsChange:=False;
  1339.   n:=0;
  1340.   while not FDQuery1.Eof do
  1341.    begin
  1342.    DBResults[n].New:=0;
  1343.    DBResults[n].ID:=FDQuery1.FieldByName('ID').AsInteger;
  1344.    DBResults[n].Client:=FDQuery1.FieldByName('Client').AsInteger;
  1345.    DBResults[n].Diet:=FDQuery1.FieldByName('Diet').AsInteger;
  1346.    DBResults[n].TMR1:=FDQuery1.FieldByName('TMR 1').AsInteger;
  1347.    DBResults[n].TMR2:=FDQuery1.FieldByName('TMR 2').AsInteger;
  1348.    DBResults[n].TMR3:=FDQuery1.FieldByName('TMR 3').AsInteger;
  1349.    DBResults[n].TMR4:=FDQuery1.FieldByName('TMR 4').AsInteger;
  1350.    DBResults[n].TMR5:=FDQuery1.FieldByName('TMR 5').AsInteger;
  1351.    DBResults[n].TMR6:=FDQuery1.FieldByName('TMR 6').AsInteger;
  1352.    DBResults[n].TMR7:=FDQuery1.FieldByName('TMR 7').AsInteger;
  1353.    DBResults[n].TMR8:=FDQuery1.FieldByName('TMR 8').AsInteger;
  1354.    DBResults[n].TMR9:=FDQuery1.FieldByName('TMR 9').AsInteger;
  1355.    DBResults[n].TMR10:=FDQuery1.FieldByName('TMR 10').AsInteger;
  1356.    DBResults[n].TMR11:=FDQuery1.FieldByName('TMR 11').AsInteger;
  1357.    DBResults[n].TMR12:=FDQuery1.FieldByName('TMR 12').AsInteger;
  1358.    DBResults[n].TMR13:=FDQuery1.FieldByName('TMR 13').AsInteger;
  1359.    DBResults[n].TMR14:=FDQuery1.FieldByName('TMR 14').AsInteger;
  1360.    DBResults[n].TMR15:=FDQuery1.FieldByName('TMR 15').AsInteger;
  1361.    DBResults[n].TMR16:=FDQuery1.FieldByName('TMR 16').AsInteger;
  1362.    DBResults[n].Parlour1:=FDQuery1.FieldByName('Parlour 1').AsInteger;
  1363.    DBResults[n].Parlour2:=FDQuery1.FieldByName('Parlour 2').AsInteger;
  1364.    DBResults[n].Parlour3:=FDQuery1.FieldByName('Parlour 3').AsInteger;
  1365.    DBResults[n].Grazing:=FDQuery1.FieldByName('Grazing').AsInteger;
  1366.    DBResults[n].ResultsID:=FDQuery1.FieldByName('ResultsID').AsInteger;
  1367.    DBResults[n].MatureBW:=FDQuery1.FieldByName('MatureBW').AsInteger;
  1368.    DBResults[n].WeekOfLactation:=FDQuery1.FieldByName('WeekOfLactation').AsInteger;
  1369.    DBResults[n].PotentialYield:=FDQuery1.FieldByName('PotentialYield').AsInteger;
  1370.    DBResults[n].Heifer3:=FDQuery1.FieldByName('Heifer-3+').AsInteger;
  1371.    DBResults[n].NoOfCows:=FDQuery1.FieldByName('NoOfCows').AsInteger;
  1372.    DBResults[n].FeedingStrategyPlan:=FDQuery1.FieldByName('FeedingStrategyPlan').AsInteger;
  1373.    DBResults[n].MilkingFrequency:=FDQuery1.FieldByName('MilkingFrequency').AsInteger;
  1374.    DBResults[n].GrazingTimeAfterMilking:=FDQuery1.FieldByName('GrazingTimeAfterMilking').AsInteger;
  1375.    DBResults[n].ParlourType:=FDQuery1.FieldByName('Parlour Type').AsInteger;
  1376.    DBResults[n].GrazingSwardLength:=FDQuery1.FieldByName('GrazingSwardLength').AsInteger;
  1377.    DBResults[n].LactorGrowth:=FDQuery1.FieldByName('LactorGrowth').AsInteger;
  1378.    DBResults[n].SizeOfAnimal:=FDQuery1.FieldByName('SizeOfAnimal').AsInteger;
  1379.    DBResults[n].JerseyBreed:=FDQuery1.FieldByName('JerseyBreed').AsInteger;
  1380.    DBResults[n].GrazingStartAfterMilking:=FDQuery1.FieldByName('GrazingStartaftermilking').AsInteger;
  1381.    DBResults[n].TMR1Type:=FDQuery1.FieldByName('TMR 1 Type').AsString;
  1382.    DBResults[n].TMR2Type:=FDQuery1.FieldByName('TMR 2 Type').AsString;
  1383.    DBResults[n].TMR3Type:=FDQuery1.FieldByName('TMR 3 Type').AsString;
  1384.    DBResults[n].TMR4Type:=FDQuery1.FieldByName('TMR 4 Type').AsString;
  1385.    DBResults[n].TMR5Type:=FDQuery1.FieldByName('TMR 5 Type').AsString;
  1386.    DBResults[n].TMR6Type:=FDQuery1.FieldByName('TMR 6 Type').AsString;
  1387.    DBResults[n].TMR7Type:=FDQuery1.FieldByName('TMR 7 Type').AsString;
  1388.    DBResults[n].TMR8Type:=FDQuery1.FieldByName('TMR 8 Type').AsString;
  1389.    DBResults[n].TMR9Type:=FDQuery1.FieldByName('TMR 9 Type').AsString;
  1390.    DBResults[n].TMR10Type:=FDQuery1.FieldByName('TMR 10 Type').AsString;
  1391.    DBResults[n].TMR11Type:=FDQuery1.FieldByName('TMR 11 Type').AsString;
  1392.    DBResults[n].TMR12Type:=FDQuery1.FieldByName('TMR 12 Type').AsString;
  1393.    DBResults[n].TMR13Type:=FDQuery1.FieldByName('TMR 13 Type').AsString;
  1394.    DBResults[n].TMR14Type:=FDQuery1.FieldByName('TMR 14 Type').AsString;
  1395.    DBResults[n].TMR15Type:=FDQuery1.FieldByName('TMR 15 Type').AsString;
  1396.    DBResults[n].TMR16Type:=FDQuery1.FieldByName('TMR 16 Type').AsString;
  1397.    DBResults[n].Parlour1Type:=FDQuery1.FieldByName('Parlour 1 Type').AsString;
  1398.    DBResults[n].Parlour2Type:=FDQuery1.FieldByName('Parlour 2 Type').AsString;
  1399.    DBResults[n].Parlour3Type:=FDQuery1.FieldByName('Parlour 3 Type').AsString;
  1400.    DBResults[n].TMR1Amount:=FDQuery1.FieldByName('TMR 1 Amount').AsString;
  1401.    DBResults[n].TMR2Amount:=FDQuery1.FieldByName('TMR 2 Amount').AsString;
  1402.    DBResults[n].TMR3Amount:=FDQuery1.FieldByName('TMR 3 Amount').AsString;
  1403.    DBResults[n].TMR4Amount:=FDQuery1.FieldByName('TMR 4 Amount').AsString;
  1404.    DBResults[n].TMR5Amount:=FDQuery1.FieldByName('TMR 5 Amount').AsString;
  1405.    DBResults[n].TMR6Amount:=FDQuery1.FieldByName('TMR 6 Amount').AsString;
  1406.    DBResults[n].TMR7Amount:=FDQuery1.FieldByName('TMR 7 Amount').AsString;
  1407.    DBResults[n].TMR8Amount:=FDQuery1.FieldByName('TMR 8 Amount').AsString;
  1408.    DBResults[n].TMR9Amount:=FDQuery1.FieldByName('TMR 9 Amount').AsString;
  1409.    DBResults[n].TMR10Amount:=FDQuery1.FieldByName('TMR 10 Amount').AsString;
  1410.    DBResults[n].TMR11Amount:=FDQuery1.FieldByName('TMR 11 Amount').AsString;
  1411.    DBResults[n].TMR12Amount:=FDQuery1.FieldByName('TMR 12 Amount').AsString;
  1412.    DBResults[n].TMR13Amount:=FDQuery1.FieldByName('TMR 13 Amount').AsString;
  1413.    DBResults[n].TMR14Amount:=FDQuery1.FieldByName('TMR 14 Amount').AsString;
  1414.    DBResults[n].TMR15Amount:=FDQuery1.FieldByName('TMR 15 Amount').AsString;
  1415.    DBResults[n].TMR16Amount:=FDQuery1.FieldByName('TMR 16 Amount').AsString;
  1416.    DBResults[n].Parlour1Amount:=FDQuery1.FieldByName('Parlour Amount 1').AsString;
  1417.    DBResults[n].Parlour2Amount:=FDQuery1.FieldByName('Parlour Amount 2').AsString;
  1418.    DBResults[n].Parlour3Amount:=FDQuery1.FieldByName('Parlour Amount 3').AsString;
  1419.    DBResults[n].Parlour4Amount:=FDQuery1.FieldByName('Parlour Amount 4').AsString;
  1420.    DBResults[n].GrazingType:=FDQuery1.FieldByName('Grazing Type').AsString;
  1421.    DBResults[n].Priceperlitre:=FDQuery1.FieldByName('Priceperlitre').AsFloat;
  1422.    DBResults[n].ConditionScore:=FDQuery1.FieldByName('ConditionScore').AsFloat;
  1423.    DBResults[n].MilkFat:=FDQuery1.FieldByName('MilkFat').AsFloat;
  1424.    DBResults[n].MilkProtein:=FDQuery1.FieldByName('MilkProtein').AsFloat;
  1425.    DBResults[n].ph1:=FDQuery1.FieldByName('pH 1').AsFloat;
  1426.    DBResults[n].ph2:=FDQuery1.FieldByName('pH 2').AsFloat;
  1427.    DBResults[n].ph3:=FDQuery1.FieldByName('pH 3').AsFloat;
  1428.    DBResults[n].ph4:=FDQuery1.FieldByName('pH 4').AsFloat;
  1429.    DBResults[n].ph5:=FDQuery1.FieldByName('pH 5').AsFloat;
  1430.    DBResults[n].ph6:=FDQuery1.FieldByName('pH 6').AsFloat;
  1431.    DBResults[n].ph7:=FDQuery1.FieldByName('pH 7').AsFloat;
  1432.    DBResults[n].ph8:=FDQuery1.FieldByName('pH 8').AsFloat;
  1433.    DBResults[n].ph9:=FDQuery1.FieldByName('pH 9').AsFloat;
  1434.    DBResults[n].ph10:=FDQuery1.FieldByName('pH 10').AsFloat;
  1435.    DBResults[n].ph11:=FDQuery1.FieldByName('pH 11').AsFloat;
  1436.    DBResults[n].ph12:=FDQuery1.FieldByName('pH 12').AsFloat;
  1437.    DBResults[n].ph13:=FDQuery1.FieldByName('pH 13').AsFloat;
  1438.    DBResults[n].ph14:=FDQuery1.FieldByName('pH 14').AsFloat;
  1439.    DBResults[n].ph15:=FDQuery1.FieldByName('pH 15').AsFloat;
  1440.    DBResults[n].ph16:=FDQuery1.FieldByName('pH 16').AsFloat;
  1441.    DBResults[n].ph17:=FDQuery1.FieldByName('pH 17').AsFloat;
  1442.    DBResults[n].ph18:=FDQuery1.FieldByName('pH 18').AsFloat;
  1443.    DBResults[n].ph19:=FDQuery1.FieldByName('pH 19').AsFloat;
  1444.    DBResults[n].ph20:=FDQuery1.FieldByName('pH 20').AsFloat;
  1445.    DBResults[n].ph21:=FDQuery1.FieldByName('pH 21').AsFloat;
  1446.    DBResults[n].ph22:=FDQuery1.FieldByName('pH 22').AsFloat;
  1447.    DBResults[n].ph23:=FDQuery1.FieldByName('pH 23').AsFloat;
  1448.    DBResults[n].ph24:=FDQuery1.FieldByName('pH 24').AsFloat;
  1449.    DBResults[n].CH4:=FDQuery1.FieldByName('CH4').AsFloat;
  1450.    DBResults[n].ConcUse:=FDQuery1.FieldByName('ConcUse kgDM/litre').AsFloat;
  1451. //   DBResults[n].ConcFeed£hdd:=FDQuery1.FieldByName('ConcFeed £/hd/d').AsFloat;
  1452. //   DBResults[n].ConcFeedpl:=FDQuery1.FieldByName('ConcFeed p/litre').AsFloat;
  1453. //   DBResults[n].AllFeed£hdd:=FDQuery1.FieldByName('AllFeeds £/hd/d').AsFloat;
  1454. //   DBResults[n].AllFeedpl:=FDQuery1.FieldByName('AllFeeds p/litre').AsFloat;
  1455. //   DBResults[n].MarginOverFeed£hdd:=FDQuery1.FieldByName('Marginoverfeed £/hd/d').AsFloat;
  1456. //   DBResults[n].MarginOverFeedpl:=FDQuery1.FieldByName('Marginoverfeed p/litre').AsFloat;
  1457. //   DBResults[n].MilkYieldAchieved:=FDQuery1.FieldByName('MilkYieldAchieved').AsFloat;
  1458. //   DBResults[n].ParlourTMR:=FDQuery1.FieldByName('ParlourTMR').AsString;
  1459. //   DBResults[n].PredictedDMI:=FDQuery1.FieldByName('PredictedDMI').AsFloat;
  1460. //   DBResults[n].PredictedForagePC:=FDQuery1.FieldByName('PredictedForagePC').AsFloat;
  1461.    inc(n);
  1462.    FDQuery1.Next;
  1463.    end;
  1464.   FDQuery1.Close;
  1465.   end;
  1466.  end
  1467. else
  1468.  begin
  1469.  DBResults:=nil;
  1470.  SetLength(DBResults,ResultsHigh);
  1471. // EnDeCryptFile(DatabaseDirectory+'\DBResults.ph6');
  1472.  OpenResults(ResultsHigh);
  1473. // EnDeCryptFile(DatabaseDirectory+'\DBResults.ph6');
  1474.  end;
  1475. end;
  1476.  
  1477. procedure TMain.InitializeDBandTables;
  1478. var
  1479. DateOfNow: Double;
  1480. MaximumComponentLength, FileSystemFlags, VolumeSerialNumber: DWORD;
  1481. StoredHardDriveNo: Int64;
  1482. Header: String;
  1483. SupS: TextFile;
  1484.  
  1485. begin
  1486. Consultant:=0; DifferentHD:=False; HardDriveNo:=0; DBMasterFeedsHigh:=0;
  1487. DBClientFeedsHigh:=0; DBPreMixFeedsHigh:=0; DBFormulationHigh:=0;
  1488. DBFarmerHigh:=0; DBResultsHigh:=0; ShutDownNow:=False;
  1489. //FullServerDB:=False;DBConnected:=False;
  1490. try
  1491. if FullServerDB then
  1492.  begin
  1493.  if FDConnection1.Ping then
  1494.   begin
  1495.   DateToRestrictCDB;
  1496.   FDConnection1.Connected:=True;
  1497.   FDTable1.TableName:='Consultant';
  1498.   FDTable1.Open;
  1499.   DBConnected:=True;
  1500.   NewClients:=False;
  1501.   NewFarmers:=False;
  1502.   NewMaster:=False;
  1503.   NewMineral:=False;
  1504.   NewBlends:=False;
  1505.   NIRS4Farm:=False;
  1506. //  Consultant:=0;
  1507.   if FDTable1.Locate('User',User,[]) then
  1508.    begin
  1509.    if FDTable1.FieldByName('Password').AsString=Password then
  1510.     begin
  1511.     AccessServer:=Now;
  1512.     GetVolumeInformationA('C:\', nil, 0, @VolumeSerialNumber,
  1513.       MaximumComponentLength, FileSystemFlags, nil, 0);
  1514.     HardDriveNo:=VolumeSerialNumber;
  1515.     Consultant:=FDTable1.FieldByName('ID').AsInteger;
  1516.     ConsultantName:=FDTable1.FieldByName('NameOfConsultant').AsString;
  1517.     ConsultantPhoneNo:=FDTable1.FieldByName('Telephone').AsString;
  1518.     StoredHardDriveNo:=FDTable1.FieldByName('SHDN').AsLargeInt;
  1519.     if StoredHardDriveNo<>HardDriveNo then
  1520.      begin
  1521.      DifferentHD:=True;
  1522.      if FirstChoice then DifferentHD:=False;
  1523.      if StoredHardDriveNo<HardDriveNo then
  1524.       DifferentHDNo:=1
  1525.      else
  1526.       DifferentHDNo:=2;
  1527.      end;
  1528.     if FDTable1.FieldByName('Client').AsInteger=1 then
  1529.      NewClients:=True;
  1530.     if FDTable1.FieldByName('MasterTable').AsInteger=1 then
  1531.      NewFarmers:=True;
  1532.     if FDTable1.FieldByName('MasterFeeds').AsInteger=1 then
  1533.      NewMaster:=True;
  1534.     if FDTable1.FieldByName('Minerals').AsInteger=1 then
  1535.      NewMineral:=True;
  1536.     if FDTable1.FieldByName('Blends').AsInteger=1 then
  1537.      NewBlends:=True;
  1538.     if FDTable1.FieldByName('Addcsv').AsInteger=1 then
  1539.      NIRS4Farm:=True;
  1540.     if (NewClients) or (NewFarmers) or (NewMaster) or (DifferentHD)
  1541.      or (NewMineral) or (NewBlends) then
  1542.      begin
  1543.      FDTable1.Edit;
  1544.      FDTable1.FieldByName('Client').AsInteger:=0;
  1545.      FDTable1.FieldByName('MasterTable').AsInteger:=0;
  1546.      FDTable1.FieldByName('MasterFeeds').AsInteger:=0;
  1547.      FDTable1.FieldByName('SHDN').AsLargeInt:=HardDriveNo;
  1548.      FDTable1.FieldByName('Minerals').AsInteger:=0;
  1549.      FDTable1.FieldByName('Blends').AsInteger:=0;
  1550.      FDTable1.Post;
  1551.      end;
  1552.     DateOfNow:=Now;
  1553.     if DateOfNow>FDTable1.FieldByName('PaidUntil').AsFloat then
  1554.      begin
  1555.      if (DateOfNow-31)>FDTable1.FieldByName('PaidUntil').AsFloat then
  1556.       ShutDownNow:=True;
  1557.      DBConnected:=False;
  1558.      FDConnection1.Connected:=False;
  1559.      end;
  1560.     end;
  1561.    end
  1562.   else
  1563.    begin
  1564.    FirstChoice:=True;
  1565.    DBConnected:=False;
  1566.    end;
  1567.   FDTable1.Close;
  1568.   if DifferentHD then
  1569.    begin
  1570.    FDTable1.TableName:='INIFiles';
  1571.    FDTable1.Open;
  1572.    if FDTable1.Locate('Consultant',Consultant,[]) then
  1573.     begin
  1574.     DBMasterFeedsHigh:=FDTable1.FieldByName('MasterFeedsHigh').AsInteger;
  1575.     DBClientFeedsHigh:=FDTable1.FieldByName('ClientFeedsHigh').AsInteger;
  1576.     DBPreMixFeedsHigh:=FDTable1.FieldByName('PreMixFeedsHigh').AsInteger;
  1577.     DBFormulationHigh:=FDTable1.FieldByName('FormulationHigh').AsInteger;
  1578.     DBFarmerHigh:=FDTable1.FieldByName('FarmerHigh').AsInteger;
  1579.     if DBFarmerHigh=0 then DBFarmerHigh:=1;
  1580.     DBResultsHigh:=FDTable1.FieldByName('ResultsHigh').AsInteger;
  1581.     end;
  1582.    FDTable1.Close;
  1583.    end;
  1584.   if (Consultant>0) and DBConnected then
  1585.    begin
  1586.    FDTable1.TableName:='Useage';
  1587.    FDTable1.Open;
  1588.    FDTable1.Append;
  1589.    FDTable1.FieldByName('Consultant').AsInteger:=Consultant;
  1590.    FDTable1.FieldByName('LastUsed').AsDateTime:=StrToDateTime(DateTimeToStr(Now));
  1591.    FDTable1.FieldByName('Version').AsString:=VersionNo;
  1592.    FDTable1.Post;
  1593.    FDTable1.Close;
  1594.    end;
  1595.   end;
  1596.  end;
  1597. //if not FirstChoice then
  1598. // begin
  1599.  SetUpDBMasterFeeds;
  1600.  SetUpDBClientFeeds;
  1601.  SetUpDBPreMixes;
  1602.  SetUpDBFarmer;
  1603.  SetUpDBFormulation;
  1604.  SetUpDBResults;
  1605.  SetUpDBFeedPrices;
  1606.  if DBConnected then DateLastUsed:=Now;
  1607.  GetMinerals;
  1608. // end;
  1609. except
  1610.  
  1611.  
  1612. end;
  1613. end;
  1614.  
  1615.  
  1616.  
  1617. procedure TMain.SpeedButton3Click(Sender: TObject);
  1618. const
  1619. PingTime=800;
  1620.  
  1621. var
  1622. n,m: Integer;
  1623. SaveCursor: TCursor;
  1624. text: String;
  1625. ComboResults,DBPingTime,NotTicked: Boolean;
  1626. Start,Stop,ElapsedTime: Integer;
  1627.  
  1628. begin
  1629. //if not DirectoryExists(GetProfile+'\OneDrive\pH6+\Database') then
  1630. //   ForceDirectories(GetProfile+'\OneDrive\pH6+\Database');
  1631. if not Administrator then
  1632.  begin
  1633.  SaveCursor:=Screen.Cursor;
  1634.  Screen.Cursor:=crHourGlass;
  1635.  DBNotConnected:=0; DBPingTime:=True;
  1636.  if DBConnected then
  1637.   begin
  1638.   if not SavingData then
  1639.    begin
  1640.    SaveToDB.Show;
  1641.    Application.ProcessMessages;
  1642.    end;
  1643.   FDConnection1.LoginPrompt:=False;
  1644.   if FDConnection1.Ping then
  1645.    begin
  1646.    FDConnection1.Connected:=True;
  1647.    end
  1648.   else
  1649.    begin
  1650.    DBConnected:=False;
  1651.    end;
  1652.   end;
  1653.  text:='';
  1654.  try
  1655.  SaveMaster;
  1656.  if MasterFeedsHigh>OldMasterFeedsHigh then OldMasterFeedsHigh:=MasterFeedsHigh;
  1657.  EnDecryptFile(DatabaseDirectory+'\DBMasterFeeds.ph6');
  1658.  if MasterFeedsHigh=OldMasterFeedsHigh then
  1659.   begin
  1660.   DeleteFile(DatabaseDirectory+'\Stored\DBMasterFeeds.ph6');
  1661.   CopyFile(PWideChar(DatabaseDirectory+'\DBMasterFeeds.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBMasterFeeds.ph6'),False);
  1662.   end;
  1663. // FileSizes(DatabaseDirectory+'\DBMasterFeeds.ph6',DatabaseDirectory+'\Stored\DBMasterFeeds.ph6');
  1664. // CopyFile(PWideChar(DatabaseDirectory+'\DBMasterFeeds.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBMasterFeeds.ph6'),False);
  1665.  except
  1666.   text:=text+'MasterFeeds not saved ';
  1667.  end;
  1668.  try
  1669.  AreAmendClient;
  1670.  ElapsedTime:=0;
  1671.  if (ClientToDB) and (DBConnected) then
  1672.   begin
  1673.   Start:=GetTickCount;
  1674.   if (FDConnection1.Ping) then
  1675.    begin
  1676.    Stop:=GetTickCount;
  1677.    ElapsedTime:=Stop-Start;
  1678.    if ElapsedTime>PingTime then DBPingTime:=False;
  1679.    DBPingTime:=True;
  1680.    if DBPingTime then
  1681.     begin
  1682.     FDTable1.TableName:='Client';
  1683.     FDTable1.Open;
  1684.     for n := 0 to Length(AmendClient)-1 do
  1685.      begin
  1686.      if AmendClient[n].New=-1 then //delete
  1687.       begin
  1688.       if FDTable1.Locate('Consultant;ID',VarArrayOf([Consultant,AmendClient[n].ID]),[]) then
  1689.        begin
  1690.        FDTable1.Delete;
  1691.        end;
  1692.       end
  1693.      else if AmendClient[n].New=1 then //insert
  1694.       begin
  1695.       for m := 0 to Length(DBClientFeeds)-1 do
  1696.        if AmendClient[n].ID=DBClientFeeds[m].ID then
  1697.         begin
  1698.         InsertClient(DBClientFeeds[m],1);
  1699.         DBClientFeeds[m].New:=0;
  1700.         end;
  1701.       end
  1702.      else if AmendClient[n].New=-2 then //append new cost or new DM
  1703.       begin
  1704.       for m := 0 to Length(DBClientFeeds)-1 do
  1705.        if AmendClient[n].ID=DBClientFeeds[m].ID then
  1706.         begin
  1707.         InsertClient(DBClientFeeds[m],-2);
  1708.         DBClientFeeds[m].New:=0;
  1709.         AmendClient[n].New:=0;
  1710.         end;
  1711.       end
  1712.      else if AmendClient[n].New=-3 then //append new GasA - multiplier for fNDF
  1713.       begin
  1714.       for m := 0 to Length(DBClientFeeds)-1 do
  1715.        if AmendClient[n].ID=DBClientFeeds[m].ID then
  1716.         begin
  1717.         InsertClient(DBClientFeeds[m],-3);
  1718.         DBClientFeeds[m].New:=0;
  1719.         AmendClient[n].New:=0;
  1720.         end;
  1721.       end;
  1722.      end;
  1723.     FDTable1.Close;
  1724.     if ClientDelDB then
  1725.      begin
  1726.      ClientDelDB:=False;
  1727.      end;
  1728.     ClientToDB:=False;
  1729.     end
  1730.    else   //if DBPingTime is false
  1731.     begin
  1732.     DBNotConnected:=1;
  1733.     DBConnected:=False;
  1734. //   Stop:=GetTickCount;
  1735. //   ElapsedTime:=Stop-Start;
  1736.     end;
  1737.    end;
  1738.   end;
  1739.  SaveClient;
  1740.  if ClientFeedsHigh>OldClientFeedsHigh then OldClientFeedsHigh:=ClientFeedsHigh;
  1741.  EnDecryptFile(DatabaseDirectory+'\DBClientFeeds.ph6');
  1742.  if ClientFeedsHigh=OldClientFeedsHigh then
  1743.   begin
  1744.   DeleteFile(DatabaseDirectory+'\Stored\DBClientFeeds.ph6');
  1745.   CopyFile(PWideChar(DatabaseDirectory+'\DBClientFeeds.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBClientFeeds.ph6'),False);
  1746.   end;
  1747. //FileSizes(DatabaseDirectory+'\DBClientFeeds.ph6',DatabaseDirectory+'\Stored\DBClientFeeds.ph6');
  1748. //CopyFile(PWideChar(DatabaseDirectory+'\DBClientFeeds.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBClientFeeds.ph6'),False);
  1749.  SaveToDB.CheckBox1.Checked:=True;
  1750.  if (Consultant=1) or (Consultant=2) then
  1751.   SaveToDB.Label1.Caption:=IntToStr(ElapsedTime);
  1752.  if not SavingData then Application.ProcessMessages;
  1753.  except
  1754.   DBNotConnected:=1;
  1755. // ClientFeedsHigh:=Length(DBClientFeeds);
  1756.   SaveClient;
  1757.   if ClientFeedsHigh>OldClientFeedsHigh then OldClientFeedsHigh:=ClientFeedsHigh;
  1758.   EnDecryptFile(DatabaseDirectory+'\DBClientFeeds.ph6');
  1759.   if ClientFeedsHigh=OldClientFeedsHigh then
  1760.    begin
  1761.    DeleteFile(DatabaseDirectory+'\Stored\DBClientFeeds.ph6');
  1762.    CopyFile(PWideChar(DatabaseDirectory+'\DBClientFeeds.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBClientFeeds.ph6'),False);
  1763.    end;
  1764. // FileSizes(DatabaseDirectory+'\DBClientFeeds.ph6',DatabaseDirectory+'\Stored\DBClientFeeds.ph6');
  1765. // CopyFile(PWideChar(DatabaseDirectory+'\DBClientFeeds.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBClientFeeds.ph6'),False);
  1766.   text:=text+'Client Feeds not saved to database. Try running pH6+ again and then close down. ';
  1767.   FDTable1.Close;
  1768.  end;
  1769.  try
  1770.  AreAmendPreMixes;
  1771.  ElapsedTime:=0;
  1772.  if (PreMixesToDB) and (DBConnected) then
  1773.   begin
  1774.   Start:=GetTickCount;
  1775.   if (FDConnection1.Ping) then
  1776.    begin
  1777.    Stop:=GetTickCount;
  1778.    ElapsedTime:=Stop-Start;
  1779.    FDTable1.TableName:='Blends';
  1780.    FDTable1.Open;
  1781.    for n := 0 to Length(AmendPreMixes)-1 do
  1782.     begin
  1783.     if AmendPreMixes[n].New=-4 then
  1784.      begin
  1785.      if FDTable1.Locate('Consultant;ID',VarArrayOf([Consultant,AmendPreMixes[n].ID]),[]) then
  1786.       begin
  1787.       FDTable1.Delete;
  1788.       end;
  1789.      end;
  1790.     for m := 0 to Length(DBPreMixes)-1 do
  1791.      if AmendPreMixes[n].ID=DBPreMixes[m].ID then
  1792.       begin
  1793.       InsertPreMixes(DBPreMixes[m],AmendPreMixes[n].New);
  1794.       DBPreMixes[m].New:=0;
  1795.       end;
  1796.     end;
  1797.    FDTable1.Close;
  1798.    if PreMixesDelDB then
  1799.     begin
  1800.     PreMixesDelDB:=False;
  1801.     end;
  1802.    PreMixesToDB:=False;
  1803.    end
  1804.   else
  1805.    begin
  1806.    DBNotConnected:=1;
  1807.    DBConnected:=False;
  1808.    Stop:=GetTickCount;
  1809.    ElapsedTime:=Stop-Start;
  1810.    end;
  1811.   end;
  1812.  SavePreMixes;
  1813.  PreMixFeedsHigh:=Length(DBPreMixes);
  1814.  if PreMixFeedsHigh>OldPreMixFeedsHigh then OldPreMixFeedsHigh:=PreMixFeedsHigh;
  1815.  EnDecryptFile(DatabaseDirectory+'\DBPreMixes.ph6');
  1816.  if PreMixFeedsHigh=OldPreMixFeedsHigh then
  1817.   begin
  1818.   DeleteFile(DatabaseDirectory+'\Stored\DBPreMixes.ph6');
  1819.   CopyFile(PWideChar(DatabaseDirectory+'\DBPreMixes.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBPreMixes.ph6'),False);
  1820.   end;
  1821. //FileSizes(DatabaseDirectory+'\DBPreMixes.ph6',DatabaseDirectory+'\Stored\DBPreMixes.ph6');
  1822. //CopyFile(PWideChar(DatabaseDirectory+'\DBPreMixes.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBPreMixes.ph6'),False);
  1823.  SaveToDB.CheckBox2.Checked:=True;
  1824.  if (Consultant=1) or (Consultant=2) then
  1825.   SaveToDB.Label2.Caption:=IntToStr(ElapsedTime);
  1826.  if not SavingData then Application.ProcessMessages;
  1827.  except
  1828.   DBNotConnected:=1;
  1829.   PreMixFeedsHigh:=Length(DBPreMixes);
  1830.   SavePreMixes;
  1831.   if PreMixFeedsHigh>OldPreMixFeedsHigh then OldPreMixFeedsHigh:=PreMixFeedsHigh;
  1832.   EnDecryptFile(DatabaseDirectory+'\DBPreMixes.ph6');
  1833.   if PreMixFeedsHigh=OldPreMixFeedsHigh then
  1834.    begin
  1835.    DeleteFile(DatabaseDirectory+'\Stored\DBPreMixFeeds.ph6');
  1836.    CopyFile(PWideChar(DatabaseDirectory+'\DBPreMixFeeds.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBPreMixFeeds.ph6'),False);
  1837.    end;
  1838. // FileSizes(DatabaseDirectory+'\DBPreMixes.ph6',DatabaseDirectory+'\Stored\DBPreMixes.ph6');
  1839. // CopyFile(PWideChar(DatabaseDirectory+'\DBPreMixes.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBPreMixes.ph6'),False);
  1840.   text:=text+'PreMixes not saved to database. Try running pH6+ again and then close down. ';
  1841.   FDTable1.Close;
  1842.  end;
  1843.  try
  1844.  SaveFarmer;
  1845.  FarmerHigh:=Length(DBFarmer);
  1846.  if FarmerHigh>OldFarmerHigh then OldFarmerHigh:=FarmerHigh;
  1847.  EnDecryptFile(DatabaseDirectory+'\DBFarmer.ph6');
  1848.  if FarmerHigh=OldFarmerHigh then
  1849.   begin
  1850.   DeleteFile(DatabaseDirectory+'\Stored\DBFarmer.ph6');
  1851.   CopyFile(PWideChar(DatabaseDirectory+'\DBFarmer.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBFarmer.ph6'),False);
  1852.   end;
  1853. //FileSizes(DatabaseDirectory+'\DBFarmer.ph6',DatabaseDirectory+'\Stored\DBFarmer.ph6');
  1854. //CopyFile(PWideChar(DatabaseDirectory+'\DBFarmer.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBFarmer.ph6'),False);
  1855.  ElapsedTime:=0;
  1856.  if (FarmerToDB) and (DBConnected) then
  1857.   begin
  1858.   Start:=GetTickCount;
  1859.   if (FDConnection1.Ping) then
  1860.    begin
  1861.    Stop:=GetTickCount;
  1862.    ElapsedTime:=Stop-Start;
  1863.    FDTable1.TableName:='MasterTable';
  1864.    FDTable1.Open;
  1865.    for n := 0 to Length(AmendFarmer)-1 do
  1866.     begin
  1867.     if AmendFarmer[n].New=-1 then //delete
  1868.      begin
  1869.      if FDTable1.Locate('Consultant;ID',VarArrayOf([Consultant,AmendFarmer[n].ID]),[]) then
  1870.       begin
  1871.       FDTable1.Delete;
  1872.       end;
  1873.      end
  1874.     else if AmendFarmer[n].New=1 then //insert
  1875.      begin
  1876.      for m := 0 to Length(DBFarmer)-1 do
  1877.       if AmendFarmer[n].ID=DBFarmer[m].DietID then
  1878.        begin
  1879.        InsertFarmer(DBFarmer[m],1);
  1880.      //get ID and alter results to this
  1881.        DBFarmer[m].DietID:=FDTable1.FieldByName('ID').AsInteger;
  1882.        DBFarmer[m].New:=0;
  1883.        AmendFarmer[n].New:=0;
  1884.        end;
  1885.      end
  1886.     else if AmendFarmer[n].New=-2 then
  1887.      begin
  1888.      for m := 0 to Length(DBFarmer)-1 do
  1889.       if AmendFarmer[n].ID=DBFarmer[m].DietID then
  1890.        begin
  1891.        InsertFarmer(DBFarmer[m],-2);
  1892.        DBFarmer[m].New:=0;
  1893.        AmendFarmer[n].New:=0;
  1894.        end;
  1895.      end;
  1896.     end;
  1897.    FDTable1.Close;
  1898.    if FarmerDelDB then
  1899.     begin
  1900.     FarmerDelDB:=False;
  1901.     end;
  1902.    FarmerToDB:=False;
  1903. // Sleep(500);
  1904.    end
  1905.   else
  1906.    begin
  1907.    DBNotConnected:=1;
  1908.    DBConnected:=False;
  1909.    Stop:=GetTickCount;
  1910.    ElapsedTime:=Stop-Start;
  1911.    end;
  1912.   end;
  1913.  SaveToDB.CheckBox3.Checked:=True;
  1914.  if (Consultant=1) or (Consultant=2) then
  1915.   SaveToDB.Label3.Caption:=IntToStr(ElapsedTime);
  1916.  if not SavingData then Application.ProcessMessages;
  1917.  except
  1918.   DBNotConnected:=1;
  1919.   FarmerHigh:=Length(DBFarmer);
  1920.   text:=text+'Farmer not saved to database ';
  1921.   FDTable1.Close;
  1922.  end;
  1923.  try
  1924.  AreAmendFormulation;
  1925.  ElapsedTime:=0;
  1926.  if (FormulationToDB) and (DBConnected) then
  1927.   begin
  1928.   Start:=GetTickCount;
  1929.   if (FDConnection1.Ping)  then
  1930.    begin
  1931.    Stop:=GetTickCount;
  1932.    ElapsedTime:=Stop-Start;
  1933.    FDTable1.TableName:='Formulation';
  1934.    FDTable1.Open;
  1935.    for n := 0 to Length(AmendFormulation)-1 do
  1936.     begin
  1937.     if AmendFormulation[n].New=-1 then //delete
  1938.      begin
  1939.      if FDTable1.Locate('Consultant;ID',VarArrayOf([Consultant,AmendFormulation[n].ID]),[]) then
  1940.       begin
  1941.       FDTable1.Delete;
  1942.       end;
  1943.      end
  1944.     else if AmendFormulation[n].New=1 then //insert
  1945.      begin
  1946.      for m := 0 to Length(DBFormulation)-1 do
  1947.       if AmendFormulation[n].ID=DBFormulation[m].ID then
  1948.        begin
  1949.        InsertFormulation(DBFormulation[m]);
  1950.       //get ID and alter results to this
  1951.        DBFormulation[m].New:=0;
  1952.        AmendFormulation[n].New:=0;
  1953.        end;
  1954.      end;
  1955.     end;
  1956.    FDTable1.Close;
  1957.    if FormulationDelDB then
  1958.     begin
  1959.     FormulationDelDB:=False;
  1960.     end;
  1961.    FormulationToDB:=False;
  1962. // Sleep(250);
  1963.    end
  1964.   else
  1965.    begin
  1966.    DBNotConnected:=1;
  1967.    DBConnected:=False;
  1968.    Stop:=GetTickCount;
  1969.    ElapsedTime:=Stop-Start;
  1970.    end;
  1971.   end;
  1972.  SaveFormulations;
  1973.  FormulationHigh:=Length(DBFormulation);
  1974.  if FormulationHigh>OldFormulationHigh then OldFormulationHigh:=FormulationHigh;
  1975.  EnDecryptFile(DatabaseDirectory+'\DBFormulation.ph6');
  1976.  if FormulationHigh=OldFormulationHigh then
  1977.   begin
  1978.   DeleteFile(DatabaseDirectory+'\Stored\DBFormulation.ph6');
  1979.   CopyFile(PWideChar(DatabaseDirectory+'\DBFormulation.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBFormulation.ph6'),False);
  1980.   end;
  1981. //FileSizes(DatabaseDirectory+'\DBFormulation.ph6',DatabaseDirectory+'\Stored\DBFormulation.ph6');
  1982. //CopyFile(PWideChar(DatabaseDirectory+'\DBFormulation.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBFormulation.ph6'),False);
  1983.  SaveToDB.CheckBox4.Checked:=True;
  1984.  if (Consultant=1) or (Consultant=2) then
  1985.   SaveToDB.Label4.Caption:=IntToStr(ElapsedTime);
  1986.  if not SavingData then Application.ProcessMessages;
  1987.  except
  1988.   DBNotConnected:=1;
  1989.   FormulationHigh:=Length(DBFormulation);
  1990.   SaveFormulations;
  1991.   if FormulationHigh>OldFormulationHigh then OldFormulationHigh:=FormulationHigh;
  1992.   EnDecryptFile(DatabaseDirectory+'\DBFormulation.ph6');
  1993.   if FormulationHigh=OldFormulationHigh then
  1994.    begin
  1995.    DeleteFile(DatabaseDirectory+'\Stored\DBFormulation.ph6');
  1996.    CopyFile(PWideChar(DatabaseDirectory+'\DBFormulation.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBFormulation.ph6'),False);
  1997.    end;
  1998. // FileSizes(DatabaseDirectory+'\DBFormulation.ph6',DatabaseDirectory+'\Stored\DBFormulation.ph6');
  1999. // CopyFile(PWideChar(DatabaseDirectory+'\DBFormulation.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBFormulation.ph6'),False);
  2000.   text:=text+'Formulation not saved to database. Try running pH6+ again and then close down. ';
  2001.   FDTable1.Close;
  2002.  end;
  2003.  try
  2004.  if not SavingData then Application.ProcessMessages;
  2005.  AreAmendResults;
  2006.  ElapsedTime:=0;
  2007.  ComboResults:=False;
  2008.  if (ResultsToDB) and (DBConnected) then
  2009.   begin
  2010.   NotTicked:=False;
  2011.   Start:=GetTickCount;
  2012.   if (FDConnection1.Ping) then
  2013.    begin
  2014.    Stop:=GetTickCount;
  2015.    ElapsedTime:=Stop-Start;
  2016.    if ElapsedTime>PingTime then DBPingTime:=False;
  2017.    if DBPingTime then
  2018.     begin
  2019.     FDTable1.TableName:='Results';
  2020.     FDTable1.Open;
  2021.     for n := 0 to Length(AmendResults)-1 do
  2022.      begin
  2023.      if AmendResults[n].New=-4 then
  2024.       begin
  2025.       ComboResults:=True;
  2026.       if FDTable1.Locate('Consultant;Diet',VarArrayOf([Consultant,AmendResults[n].ID]),[]) then
  2027.        begin
  2028. //       text:=IntToStr(FDTable1.FieldByName('ID').AsInteger);
  2029. //       ShowMessage(text);
  2030. {       with FDQuery1 do
  2031.         begin
  2032.         DisableControls;
  2033.         Close;
  2034.         SQL.Clear;
  2035.         SQL.Add('DELETE FROM Results');
  2036.         SQL.Add('WHERE  Consultant =:apptype');
  2037.         SQL.Add('AND  Diet =:apptype1');
  2038.         Params[0].DataType:=ftInteger;
  2039.         Params[0].Value:=Consultant;
  2040.         Params[1].DataType:=ftInteger;
  2041.         Params[1].Value:=AmendResults[n].ID;
  2042.         Execute;
  2043.         EnableControls;
  2044.         end; }
  2045. //       FDQuery1.First;
  2046. //       delete from Results where Consultant={Consultant} and Diet={[n].ID}
  2047.        FDTable1.Delete;
  2048.        DBResultsChange:=True;
  2049.        end;
  2050.       end;
  2051.      for m:=0 to Length(DBResults)-1 do
  2052.       if AmendResults[n].ID=DBResults[m].Diet then    //DBResults[m].ID
  2053.        begin
  2054.        InsertResult(DBResults[m],0);
  2055.        DBResults[m].New:=0;
  2056. //       DBResultsChange:=False;
  2057.        end;
  2058.      end;
  2059.     FDTable1.Close;
  2060.     if ComboResults then
  2061.      begin
  2062.      ResultsDelDB:=False;
  2063.      end;
  2064.     ResultsToDB:=False;
  2065.     end
  2066.    else
  2067.     begin
  2068.     DBNotConnected:=1;
  2069.     DBConnected:=False;
  2070.     NotTicked:=True;
  2071.     text:=text+'Internet connection lost! To complete saving results to central database,try running pH6+ again and then close down.';
  2072.  //   Stop:=GetTickCount;
  2073. //   ElapsedTime:=Stop-Start;
  2074.     end;
  2075.    end;
  2076.   end;
  2077.  SaveResults;
  2078.  ResultsHigh:=Length(DBResults);
  2079.  if ResultsHigh>OldResultsHigh then OldResultsHigh:=ResultsHigh;
  2080.  if ResultsHigh=OldResultsHigh then
  2081.   begin
  2082.   DeleteFile(DatabaseDirectory+'\Stored\DBResults.ph6');
  2083.   CopyFile(PWideChar(DatabaseDirectory+'\DBResults.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBResults.ph6'),False);
  2084.   end;
  2085. //FileSizes(DatabaseDirectory+'\DBResults.ph6',DatabaseDirectory+'\Stored\DBResults.ph6');
  2086. //CopyFile(PWideChar(DatabaseDirectory+'\DBResults.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBResults.ph6'),False);
  2087.  if not NotTicked then SaveToDB.CheckBox5.Checked:=True;
  2088.  if (Consultant=1) or (Consultant=2) then
  2089.   SaveToDB.Label5.Caption:=IntToStr(ElapsedTime);
  2090.  if not SavingData then Application.ProcessMessages;
  2091.  except
  2092.   DBNotConnected:=1;
  2093.   SaveResults;
  2094.   ResultsHigh:=Length(DBResults);
  2095.   if ResultsHigh>OldResultsHigh then OldResultsHigh:=ResultsHigh;
  2096.   if ResultsHigh=OldResultsHigh then
  2097.    begin
  2098.    DeleteFile(DatabaseDirectory+'\Stored\DBResults.ph6');
  2099.    CopyFile(PWideChar(DatabaseDirectory+'\DBResults.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBResults.ph6'),False);
  2100.    end;
  2101. // FileSizes(DatabaseDirectory+'\DBResults.ph6',DatabaseDirectory+'\Stored\DBResults.ph6');
  2102. // CopyFile(PWideChar(DatabaseDirectory+'\DBResults.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBResults.ph6'),False);
  2103.   text:=text+'Results not saved to database. Try running pH6+ again and then close down.';
  2104.   FDTable1.Close;
  2105.  end;
  2106.  try
  2107.  ElapsedTime:=0;
  2108.  if FeedPrice[1]>0 then
  2109.   begin
  2110.   SaveFeedPrices;
  2111.   EnDecryptFile(DatabaseDirectory+'\DBFeedPrices.ph6');
  2112.   Start:=GetTickCount;
  2113.   if (FDConnection1.Ping) and (DBConnected) then
  2114.    begin
  2115.    Stop:=GetTickCount;
  2116.    ElapsedTime:=Stop-Start;
  2117.    FDTable1.TableName:='FeedPricesbyConsultant';
  2118.    FDTable1.Open;
  2119.    InsertPrices;
  2120.    FDTable1.Close;
  2121.    SaveToDB.CheckBox6.Checked:=True;
  2122.    if (Consultant=1) or (Consultant=2) then
  2123.     SaveToDB.Label6.Caption:=IntToStr(ElapsedTime);
  2124.    if not SavingData then Application.ProcessMessages;
  2125.    end;
  2126.   end
  2127.  else
  2128.   begin
  2129.   DeleteFile(DatabaseDirectory+'\DBFeedPrices.ph6');
  2130.   CopyFile(PWideChar(DatabaseDirectory+'\Daily\DBFeedPrices.ph6'),PWideChar(DatabaseDirectory+'\DBFeedPrices.ph6'),False);
  2131.   SaveToDB.CheckBox6.Checked:=True;
  2132.   if (Consultant=1) or (Consultant=2) then
  2133.    SaveToDB.Label6.Caption:=IntToStr(ElapsedTime);
  2134.   if not SavingData then Application.ProcessMessages;
  2135.   end;
  2136.  except
  2137.   DeleteFile(DatabaseDirectory+'\DBFeedPrices.ph6');
  2138.   CopyFile(PWideChar(DatabaseDirectory+'\Daily\DBFeedPrices.ph6'),PWideChar(DatabaseDirectory+'\DBFeedPrices.ph6'),False);
  2139. // CopyFile(PWideChar(DatabaseDirectory+'\DBFeedPrices.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBFeedPrices.ph6'),False);
  2140. // text:=text+'Feed Prices not saved to database ';
  2141.   FDTable1.Close;
  2142.  end;
  2143. //CopyFile(PWideChar(DatabaseDirectory+'\DBFeedPrices.ph6'),PWideChar(GetProfile+'\OneDrive\pH6+\Database\DBFeedPrices.ph6'),False);
  2144.  try
  2145.  if DBConnected then
  2146.   if FDConnection1.Ping then
  2147.    begin
  2148.    FDTable1.TableName:='INIFiles';
  2149.    FDTable1.Open;
  2150.    AmendINI;
  2151.    FDTable1.Close;
  2152.    end;
  2153.  except
  2154.   text:=text+'INI Files not saved to database';
  2155.   FDTable1.Close;
  2156.  end;
  2157.  FDConnection1.Connected:=False;
  2158.  if rTranslate.no225<>'' then
  2159.   begin
  2160.   DeleteFile(DatabaseDirectory+'\Stored\DBFeedLabels.ph6');
  2161.   CopyFile(PWideChar(DatabaseDirectory+'\DBFeedLabels.ph6'),PWideChar(DatabaseDirectory+'\Stored\DBFeedLabels.ph6'),False);
  2162.   end;
  2163. //FileSizes(DatabaseDirectory+'\DBFeedLabels.ph6',DatabaseDirectory+'\Stored\DBFeedLabels.ph6');
  2164.  if text<>'' then
  2165.   ShowMessage(text);
  2166.  Screen.Cursor:=SaveCursor;
  2167.  end;
  2168. Application.Terminate;
  2169. end;
  2170.  
  2171.  
  2172. procedure TMain.GetFeedOrder(Category,Name,AmountDiet1,AmountDiet2,
  2173.                AmountDiet3,AmountDiet4,AmountDiet5: String;FeedNo: Integer;
  2174.                var p: Integer);
  2175. var
  2176. m: Integer;
  2177.  
  2178. begin
  2179. if FeedLength[FeedNo].Start>0 then
  2180.  for m:=FeedLength[FeedNo].Start-1 to FeedLength[FeedNo].Finish-1 do
  2181.   begin
  2182.   FeedOrder[m,1]:=Category;
  2183.   FeedOrder[m,2]:=Name;
  2184.   if FeedLength[FeedNo].Start=FeedLength[FeedNo].Finish then
  2185.    begin
  2186.    FeedOrder[m,3]:=AmountDiet1;
  2187.    FeedOrder[m,4]:=AmountDiet2;
  2188.    FeedOrder[m,5]:=AmountDiet3;
  2189.    FeedOrder[m,6]:=AmountDiet4;
  2190.    FeedOrder[m,7]:=AmountDiet5;
  2191.    FeedOrder[m,8]:=AmountDiet1;
  2192.    FeedOrder[m,9]:=AmountDiet2;
  2193.    FeedOrder[m,10]:=AmountDiet3;
  2194.    FeedOrder[m,11]:=AmountDiet4;
  2195.    FeedOrder[m,12]:=AmountDiet5;
  2196.    end
  2197.   else
  2198.    begin
  2199.    if AmountDiet1='' then FeedOrder[m,3]:='0' else
  2200.     FeedOrder[m,3]:=FloatToStr(StrToFloat(AmountDiet1)*PMAmount[p]/100);
  2201.    if AmountDiet2='' then FeedOrder[m,4]:='0' else
  2202.     FeedOrder[m,4]:=FloatToStr(StrToFloat(AmountDiet2)*PMAmount[p]/100);
  2203.    if AmountDiet3='' then FeedOrder[m,5]:='0' else
  2204.     FeedOrder[m,5]:=FloatToStr(StrToFloat(AmountDiet3)*PMAmount[p]/100);
  2205.    if AmountDiet4='' then FeedOrder[m,6]:='0' else
  2206.     FeedOrder[m,6]:=FloatToStr(StrToFloat(AmountDiet4)*PMAmount[p]/100);
  2207.    if AmountDiet5='' then FeedOrder[m,7]:='0' else
  2208.     FeedOrder[m,7]:=FloatToStr(StrToFloat(AmountDiet5)*PMAmount[p]/100);
  2209.    FeedOrder[m,8]:=FeedOrder[m,3];
  2210.    FeedOrder[m,9]:=FeedOrder[m,4];
  2211.    FeedOrder[m,10]:=FeedOrder[m,5];
  2212.    FeedOrder[m,11]:=FeedOrder[m,6];
  2213.    FeedOrder[m,12]:=FeedOrder[m,7];
  2214.    inc(p);
  2215.    end;
  2216.  
  2217.   if FeedOrder[m,3]='' then FeedOrder[m,3]:='0';
  2218.   if FeedOrder[m,4]='' then FeedOrder[m,4]:='0';
  2219.   if FeedOrder[m,5]='' then FeedOrder[m,5]:='0';
  2220.   if FeedOrder[m,6]='' then FeedOrder[m,6]:='0';
  2221.   if FeedOrder[m,7]='' then FeedOrder[m,7]:='0';
  2222.   if FeedOrder[m,8]='' then FeedOrder[m,8]:='0';
  2223.   if FeedOrder[m,9]='' then FeedOrder[m,9]:='0';
  2224.   if FeedOrder[m,10]='' then FeedOrder[m,10]:='0';
  2225.   if FeedOrder[m,11]='' then FeedOrder[m,11]:='0';
  2226.   if FeedOrder[m,12]='' then FeedOrder[m,12]:='0';
  2227.   end;
  2228. end;
  2229.  
  2230. procedure TMain.btnRunClick(Sender: TObject);
  2231. const
  2232. RoboticsYield=10; //15
  2233. MaxParlourPerMeal=6;
  2234.  
  2235. var
  2236. MatProtein,ProteinWt,ProteinLoss,BodyProtein,LostProtein,BodyProteinLoss,BodyProteinGain: Single;
  2237. MEGReq,MPGReq: array[0..4] of Single;
  2238. {Start,Finish,}n,m,p,counter,counter2,Pass,PassUpper,WeekOfLactation,
  2239. FinalCount,YearOfLactation,TimeToStart,TimeToFinish{,PBarCount,PBar}: Integer;
  2240. CanRun: Boolean;
  2241. DMImax,DMDiet1,DMDiet2,DMDiet3,DMDiet4,DMDiet5,Lignin,PF,
  2242. MCS,TotalDM: Single;
  2243. SaveCursor: TCursor;
  2244.  
  2245. text: String;
  2246.  
  2247. IngredientDMzero: array of Integer;
  2248.  
  2249. begin
  2250. IMustSave:=True; WhyWontItWork:=0;
  2251. CanRun:=True;
  2252. IngredientDMzero:=nil;
  2253. SetLength(IngredientDMzero,rFeedInfo.iNoFeeds);
  2254. for n := 0 to rFeedInfo.iNoFeeds-1 do
  2255.  begin
  2256.  if rFeedInfo.TMRFeed[n].DM=0 then
  2257.   begin
  2258.   CanRun:=False;
  2259.   IngredientDMzero[n]:=n+1;
  2260.   end;
  2261.  end;
  2262.  
  2263. if CanRun = false then //not CanRun then
  2264.  begin
  2265.  text:='';
  2266.  for n := 0 to rFeedInfo.iNoFeeds-1 do
  2267.   if IngredientDMzero[n]>0 then
  2268.    text:=text+IntToStr(IngredientDMzero[n])+', ';
  2269.  ShowMessage('Some ingredients aren''t entered correctly. The Ingredient no is: '+text);
  2270.  end
  2271. else
  2272. begin
  2273. try
  2274. //Start:=GetTickCount;
  2275. SaveCursor:=Screen.Cursor;
  2276. Screen.Cursor:=crHourGlass;
  2277. //ProgressBar1.Position := 0;
  2278. //ProgressBar1.Max := 100;
  2279. //PBarCount:=0; {PBar:=0;}
  2280. //FeedingStrategy.FormDeactivate must be run here in order that correct
  2281. //Grazing is calculated from TMRRobotic and Milk Yield
  2282. FeedingStrategy.FormActivate(FeedingStrategy);
  2283. FeedingStrategy.FormDeactivate(FeedingStrategy);
  2284. if TMRRobotic then
  2285.  begin
  2286. // if FeedingStrategy.ComboBox5.Text<>'' then
  2287. //  FeedingStrategy.ComboBox5Change(FeedingStrategy);
  2288.  if FeedingStrategy.ComboBox6.Text<>'' then
  2289.   begin
  2290.   rFeedInfo.iLiquid:=1;
  2291.   end
  2292.  else
  2293.   rFeedInfo.iLiquid:=0;
  2294.  end;
  2295. //Reset all TMR amounts
  2296. Instant.FillEditType;
  2297. Instant.AddFeeds(EditTypeStringArray,1);
  2298.  
  2299. //Instant.ComboBox1Change(Instant);
  2300. if LeftStr(Instant.Edit66.Text,1)='-' then
  2301.  begin
  2302.  rFeedInfo.DietToFed[1]:=True;
  2303.  DryCow:=True;
  2304.  end
  2305. else
  2306.  begin
  2307.  DryCow:=False;
  2308.  end;
  2309. for n:=0 to 2 do
  2310.  for m:=0 to UpperLimit do
  2311.   begin
  2312.   rNutrientsAbsorbed.DMI[n,m]:=0;
  2313.   rNutrientsAbsorbed.GrazingDMI[n,m]:=0;
  2314.   rNutrientsAbsorbed.ParlourDMI[n,m]:=0;
  2315.   rNutrientsAbsorbed.RoboticDMI[n,m]:=0;
  2316.   rNutrientsAbsorbed.LiquidDMI[n,m]:=0;
  2317.   end;
  2318. pH6:=True; TMROnlyGS:=True;
  2319. ptrFeedInfo:=@rFeedInfo;
  2320. ptrNutAbsorbed:=@rNutrientsAbsorbed;
  2321. ptrAnimal:=@Animal;
  2322. AcidNeutralised:=1;
  2323. if Instant.Label63.Caption='' then
  2324.  rFeedInfo.Fixed:=0
  2325. else
  2326.  rFeedInfo.Fixed:=StrToFloat(Instant.Label63.Caption);
  2327. //if SingleRun then
  2328. // begin
  2329.  Animal.MatureWeight:=Round(StrToInt(Instant.Edit61.Text)/kgToOther);
  2330.  if Beef then
  2331.   Animal.MatureCS:=4.25
  2332.  else
  2333.   Animal.MatureCS:=StrToFloat(Instant.Edit62.Text);
  2334. // end
  2335. //else
  2336. // begin
  2337. // Animal.MatureWeight:=Round(StrToInt(CowF.Edit1.Text)/kgToOther);
  2338. // Animal.MatureCS:=StrToFloat(CowF.Edit2.Text);
  2339. // end;
  2340. if Beef then
  2341.  begin
  2342.  if SingleRun then
  2343.   begin
  2344.   Animal.WeightArray[2,0]:=StrToInt(Instant.Edit66.Text)/kgToOther;
  2345.   Animal.CS[2,0]:=StrToFloat(Instant.Edit62.Text);
  2346.   end
  2347.  else
  2348.   begin
  2349. //  Animal.WeightArray[2,0]:=StrToInt(CowF.Edit12.Text)/kgToOther;
  2350. //  Animal.CS[2,0]:=StrToFloat(CowF.Edit13.Text);
  2351.   end;
  2352.  BodyComposition(ptrAnimal,1,0);
  2353.  Animal.DaysInMonth:=7;
  2354.  end;
  2355. if SingleRun then
  2356.  begin
  2357.  Mature(Round(StrToInt(Instant.Edit61.Text)/kgToOther),
  2358.         Animal.MatureCS);
  2359. // if LeftStr(Instant.Edit66.Text,1)<>'-' then
  2360.   for n:=2 to 5 do
  2361.    rFeedInfo.DietToFed[n]:=False;
  2362.  if Instant.RadioButton1.Checked then
  2363.   begin
  2364.   SRLactNo:=0;
  2365.   if LeftStr(Instant.Edit66.Text,1)='-' then
  2366.    begin
  2367.    HerdProbsS[SRLactNo,0]:=0;
  2368.    HerdProbsS[1,0]:=0;
  2369.    HerdProbsS[2,0]:=0;
  2370.    HerdProbsS[SRLactNo,3]:=1;
  2371.    HerdProbsS[SRLactNo,4]:=1;
  2372.    end
  2373.   else
  2374.    begin
  2375.    HerdProbsS[SRLactNo,0]:=1;
  2376.    HerdProbsS[1,0]:=0;
  2377.    HerdProbsS[2,0]:=0;
  2378.    HerdProbsS[SRLactNo,3]:=0;
  2379.    HerdProbsS[SRLactNo,4]:=0;
  2380.    end;
  2381.   LactationNo[1]:=1;
  2382.   LactationNo[2]:=0;
  2383.   LactationNo[3]:=0;
  2384.   if LeftStr(Instant.Edit66.Text,1)='-' then
  2385.    Animal.Weight:=Round(0.8*StrToInt(Instant.Edit61.Text));
  2386.   end
  2387.  else if Instant.RadioButton2.Checked then
  2388.   begin
  2389.   SRLactNo:=1;
  2390.   if LeftStr(Instant.Edit66.Text,1)='-' then
  2391.    begin
  2392.    HerdProbsS[SRLactNo,0]:=0;
  2393.    HerdProbsS[0,0]:=0;
  2394.    HerdProbsS[2,0]:=0;
  2395.    HerdProbsS[SRLactNo,3]:=1;
  2396.    HerdProbsS[SRLactNo,4]:=1;
  2397.    end
  2398.   else
  2399.    begin
  2400.    HerdProbsS[SRLactNo,0]:=1;
  2401.    HerdProbsS[0,0]:=0;
  2402.    HerdProbsS[2,0]:=0;
  2403.    HerdProbsS[SRLactNo,3]:=0;
  2404.    HerdProbsS[SRLactNo,4]:=0;
  2405.    end;
  2406.   LactationNo[1]:=0;
  2407.   LactationNo[2]:=1;
  2408.   LactationNo[3]:=0;
  2409.   if LeftStr(Instant.Edit66.Text,1)='-' then
  2410.    Animal.Weight:=Round(0.9*StrToInt(Instant.Edit61.Text));
  2411.   end
  2412.  else
  2413.   begin
  2414.   SRLactNo:=2;
  2415.   if LeftStr(Instant.Edit66.Text,1)='-' then
  2416.    begin
  2417.    HerdProbsS[SRLactNo,0]:=0;
  2418.    HerdProbsS[0,0]:=0;
  2419.    HerdProbsS[1,0]:=0;
  2420.    HerdProbsS[SRLactNo,3]:=1;
  2421.    HerdProbsS[SRLactNo,4]:=1;
  2422.    end
  2423.   else
  2424.    begin
  2425.    HerdProbsS[SRLactNo,0]:=1;
  2426.    HerdProbsS[0,0]:=0;
  2427.    HerdProbsS[1,0]:=0;
  2428.    HerdProbsS[SRLactNo,3]:=0;
  2429.    HerdProbsS[SRLactNo,4]:=0;
  2430.    end;
  2431.   LactationNo[1]:=0;
  2432.   LactationNo[2]:=0;
  2433.   LactationNo[3]:=1;
  2434.   end;
  2435.  if Beef then
  2436.   begin
  2437.   SRLactNo:=2;
  2438.   HerdProbsS[SRLactNo,0]:=1;
  2439.   HerdProbsS[0,0]:=0;
  2440.   HerdProbsS[1,0]:=0;
  2441.   LactationNo[1]:=0;
  2442.   LactationNo[2]:=0;
  2443.   LactationNo[3]:=1;
  2444.   end;
  2445.  rFeedInfo.Diet:=1;
  2446.  rFeedInfo.WeekToEnd[1]:=Round(LactationLength/DaysInWeek);
  2447.  DayNo[1]:=StrToInt(Instant.Edit66.Text)*DaysInWeek-DaysInWeek;
  2448.  end;
  2449. if Animal.Lactating then rFeedInfo.Lactating:=True else rFeedInfo.Lactating:=False;
  2450. rFeedInfo.Dijkstra:=False;
  2451. rFeedInfo.Mario:=False;
  2452. rFeedInfo.TMR:=True;
  2453. rFeedInfo.iDaysToRun:=20;//24
  2454. for n:=0 to 2 do
  2455.   begin
  2456.   for m:=0 to UpperLimit do
  2457.    begin
  2458.    rNutrientsAbsorbed.PotentialMilk[n,m]:=0;
  2459.    rNutrientsAbsorbed.MilkFromE[n,m]:=0;
  2460.    rNutrientsAbsorbed.MilkFromP[n,m]:=0;
  2461.    rNutrientsAbsorbed.DMI[n,m]:=0;
  2462.    rNutrientsAbsorbed.ParlourDMI[n,m]:=0;
  2463.    rNutrientsAbsorbed.GrazingDMI[n,m]:=0;
  2464.    rNutrientsAbsorbed.DietME[n,m]:=0;
  2465.    rNutrientsAbsorbed.EReq[n,m]:=0;
  2466.    rNutrientsAbsorbed.MPReq[n,m]:=0;
  2467.    rNutrientsAbsorbed.pHLim[n,m]:=0;
  2468.    rNutrientsAbsorbed.BodyWeight[n,m]:=0;
  2469.    rNutrientsAbsorbed.BodyChange[n,m]:=0;
  2470.    end;
  2471.   end;
  2472. for n:=0 to UpperLimit do
  2473.  rNutrientsAbsorbed.ProteinFromBody[n]:=0;
  2474. if not BatchMode then
  2475.  begin
  2476.  FeedOrder:=nil;
  2477.  SetLength(FeedOrder,rFeedInfo.iNoFeeds);
  2478.  end;
  2479. //get no of diets
  2480. WhyWontItWork:=1;
  2481. rFeedInfo.iNoDiets:=0;
  2482. if rFeedInfo.DietToFed[1] then rFeedInfo.iNoDiets:=1;
  2483. if rFeedInfo.DietToFed[2] then rFeedInfo.iNoDiets:=rFeedInfo.iNoDiets+1;
  2484. if rFeedInfo.DietToFed[3] then rFeedInfo.iNoDiets:=rFeedInfo.iNoDiets+1;
  2485. if rFeedInfo.DietToFed[4] then rFeedInfo.iNoDiets:=rFeedInfo.iNoDiets+1;
  2486. if rFeedInfo.DietToFed[5] then rFeedInfo.iNoDiets:=rFeedInfo.iNoDiets+1;
  2487. if FixedGrazing then PassUpper:=2 else PassUpper:=1;
  2488. Pass:=1;
  2489.   p:=0;
  2490.   GetFeedOrder(Instant.ComboBox5.Text,Instant.ComboBox1.Text,Instant.Edit6.Text,
  2491.                '','','','',1,p);
  2492.   GetFeedOrder(Instant.ComboBox6.Text,Instant.ComboBox2.Text,Instant.Edit7.Text,
  2493.                '','','','',2,p);
  2494.   GetFeedOrder(Instant.ComboBox7.Text,Instant.ComboBox3.Text,Instant.Edit8.Text,
  2495.                '','','','',3,p);
  2496.   GetFeedOrder(Instant.ComboBox8.Text,Instant.ComboBox4.Text,Instant.Edit9.Text,
  2497.                '','','','',4,p);
  2498.   GetFeedOrder(Instant.ComboBox9.Text,Instant.ComboBox10.Text,Instant.Edit13.Text,
  2499.                '','','','',5,p);
  2500.   GetFeedOrder(Instant.ComboBox11.Text,Instant.ComboBox12.Text,Instant.Edit16.Text,
  2501.                '','','','',6,p);
  2502.   GetFeedOrder(Instant.ComboBox13.Text,Instant.ComboBox14.Text,Instant.Edit18.Text,
  2503.                '','','','',7,p);
  2504.   GetFeedOrder(Instant.ComboBox15.Text,Instant.ComboBox16.Text,Instant.Edit20.Text,
  2505.                '','','','',8,p);
  2506.   GetFeedOrder(Instant.ComboBox17.Text,Instant.ComboBox18.Text,Instant.Edit22.Text,
  2507.                '','','','',9,p);
  2508.   GetFeedOrder(Instant.ComboBox19.Text,Instant.ComboBox20.Text,Instant.Edit24.Text,
  2509.                '','','','',10,p);
  2510.   GetFeedOrder(Instant.ComboBox21.Text,Instant.ComboBox22.Text,Instant.Edit26.Text,
  2511.                '','','','',11,p);
  2512.   GetFeedOrder(Instant.ComboBox23.Text,Instant.ComboBox24.Text,Instant.Edit28.Text,
  2513.                '','','','',12,p);
  2514.   GetFeedOrder(Instant.ComboBox25.Text,Instant.ComboBox26.Text,Instant.Edit1.Text,
  2515.                '','','','',13,p);
  2516.   GetFeedOrder(Instant.ComboBox27.Text,Instant.ComboBox28.Text,Instant.Edit2.Text,
  2517.                '','','','',14,p);
  2518.   GetFeedOrder(Instant.ComboBox29.Text,Instant.ComboBox30.Text,Instant.Edit3.Text,
  2519.                '','','','',15,p);
  2520.   GetFeedOrder(Instant.ComboBox31.Text,Instant.ComboBox32.Text,Instant.Edit4.Text,
  2521.                '','','','',16,p);
  2522.   //convert fresh wts (kg per mix) of feed to dry weight (g/kg given)
  2523.   //convert fresh wt given to dry wt given & sum dry weights across diets
  2524.   DMDiet1:=0; DMDiet2:=0; DMDiet3:=0; DMDiet4:=0; DMDiet5:=0;
  2525.   for counter:=0 to rFeedInfo.iNoFeeds-1 do
  2526.    begin
  2527.    if rFeedInfo.DietToFed[1] then
  2528.     begin
  2529.     FeedOrder[counter,8]:=FloatToStr(StrToFloat(FeedOrder[counter,3])*rFeedInfo.TMRFeed[counter].DM/100);
  2530.     DMDiet1:=DMDiet1+StrToFloat(FeedOrder[counter,8]);
  2531.     DMIDiet1:=DMDiet1;
  2532.     end;
  2533.    if rFeedInfo.DietToFed[2] then
  2534.     begin
  2535.     FeedOrder[counter,9]:=FloatToStr(StrToFloat(FeedOrder[counter,4])*rFeedInfo.TMRFeed[counter].DM/100);
  2536.     DMDiet2:=DMDiet2+StrToFloat(FeedOrder[counter,9]);
  2537.     end;
  2538.    if rFeedInfo.DietToFed[3] then
  2539.     begin
  2540.     FeedOrder[counter,10]:=FloatToStr(StrToFloat(FeedOrder[counter,5])*rFeedInfo.TMRFeed[counter].DM/100);
  2541.     DMDiet3:=DMDiet3+StrToFloat(FeedOrder[counter,10]);
  2542.     end;
  2543.    if rFeedInfo.DietToFed[4] then
  2544.     begin
  2545.     FeedOrder[counter,11]:=FloatToStr(StrToFloat(FeedOrder[counter,6])*rFeedInfo.TMRFeed[counter].DM/100);
  2546.     DMDiet4:=DMDiet4+StrToFloat(FeedOrder[counter,11]);
  2547.     end;
  2548.    if rFeedInfo.DietToFed[5] then
  2549.     begin
  2550.     FeedOrder[counter,12]:=FloatToStr(StrToFloat(FeedOrder[counter,7])*rFeedInfo.TMRFeed[counter].DM/100);
  2551.     DMDiet5:=DMDiet5+StrToFloat(FeedOrder[counter,12]);
  2552.     end;
  2553.    end;
  2554.   //convert DM given to g/kg DM  and calculate DM
  2555.   for counter := 1 to 5 do
  2556.    begin
  2557.    rFeedInfo.TMRDM[counter]:=0; rFeedInfo.TMRFM[counter]:=0;
  2558.    end;
  2559.   for counter:=0 to rFeedInfo.iNoFeeds-1 do
  2560.    begin
  2561.    if (rFeedInfo.DietToFed[1]) and not (CompleteFSGrazingAll) then    //FSGrazingAll[1]
  2562.     begin
  2563.     FeedOrder[counter,8]:=FloatToStr(StrToFloat(FeedOrder[counter,8])/DMDiet1*Thousand);
  2564.     if rFeedInfo.TMRFeed[counter].pemNDF>3.5 then
  2565.      begin
  2566.      rFeedInfo.TMRDM[1]:=rFeedInfo.TMRDM[1]+StrToFloat(FeedOrder[counter,8])
  2567.                          /Thousand;
  2568.      rFeedInfo.TMRFM[1]:=rFeedInfo.TMRFM[1]+StrToFloat(FeedOrder[counter,8])
  2569.                          /Thousand/rFeedInfo.TMRFeed[counter].DM*100;
  2570.      if (rFeedInfo.TMRFeed[counter].FeedType=2) and (FeedOrder[counter,8]<>'0') then
  2571.       TMROnlyGS:=False;
  2572.      end;
  2573.     end;
  2574.    if (rFeedInfo.DietToFed[2]) and not (FSGrazingAll[2]) then
  2575.     begin
  2576.     FeedOrder[counter,9]:=FloatToStr(StrToFloat(FeedOrder[counter,9])/DMDiet2*Thousand);
  2577.     if rFeedInfo.TMRFeed[counter].pemNDF>3.5 then
  2578.      begin
  2579.      rFeedInfo.TMRDM[2]:=rFeedInfo.TMRDM[2]+StrToFloat(FeedOrder[counter,9])
  2580.                          /Thousand;
  2581.      rFeedInfo.TMRFM[2]:=rFeedInfo.TMRFM[2]+StrToFloat(FeedOrder[counter,9])
  2582.                          /Thousand/rFeedInfo.TMRFeed[counter].DM*100;
  2583.      end;
  2584.     end;
  2585.    if (rFeedInfo.DietToFed[3]) and not (FSGrazingAll[3]) then
  2586.     begin
  2587.     FeedOrder[counter,10]:=FloatToStr(StrToFloat(FeedOrder[counter,10])/DMDiet3*Thousand);
  2588.     if rFeedInfo.TMRFeed[counter].pemNDF>3.5 then
  2589.      begin
  2590.      rFeedInfo.TMRDM[3]:=rFeedInfo.TMRDM[3]+StrToFloat(FeedOrder[counter,10])
  2591.                          /Thousand;
  2592.      rFeedInfo.TMRFM[3]:=rFeedInfo.TMRFM[3]+StrToFloat(FeedOrder[counter,10])
  2593.                          /Thousand/rFeedInfo.TMRFeed[counter].DM*100;
  2594.      end;
  2595.     end;
  2596.    if (rFeedInfo.DietToFed[4]) and not (FSGrazingAll[4]) then
  2597.     begin
  2598.     FeedOrder[counter,11]:=FloatToStr(StrToFloat(FeedOrder[counter,11])/DMDiet4*Thousand);
  2599.     if rFeedInfo.TMRFeed[counter].pemNDF>3.5 then
  2600.      begin
  2601.      rFeedInfo.TMRDM[4]:=rFeedInfo.TMRDM[4]+StrToFloat(FeedOrder[counter,11])
  2602.                          /Thousand;
  2603.      rFeedInfo.TMRFM[4]:=rFeedInfo.TMRFM[4]+StrToFloat(FeedOrder[counter,11])
  2604.                          /Thousand/rFeedInfo.TMRFeed[counter].DM*100;
  2605.      end;
  2606.     end;
  2607.    if (rFeedInfo.DietToFed[5]) and not (FSGrazingAll[5]) then
  2608.     begin
  2609.     FeedOrder[counter,12]:=FloatToStr(StrToFloat(FeedOrder[counter,12])/DMDiet5*Thousand);
  2610.     if rFeedInfo.TMRFeed[counter].pemNDF>3.5 then
  2611.      begin
  2612.      rFeedInfo.TMRDM[5]:=rFeedInfo.TMRDM[5]+StrToFloat(FeedOrder[counter,12])
  2613.                          /Thousand;
  2614.      rFeedInfo.TMRFM[5]:=rFeedInfo.TMRFM[5]+StrToFloat(FeedOrder[counter,12])
  2615.                          /Thousand/rFeedInfo.TMRFeed[counter].DM*100;
  2616.      end;
  2617.     end;
  2618.    end;
  2619.    if LeftStr(Instant.Edit66.Text,1)='-' then
  2620.     begin
  2621.     rFeedInfo.TMRDM[5]:=rFeedInfo.TMRDM[1];
  2622.     rFeedInfo.TMRDM[4]:=rFeedInfo.TMRDM[1];
  2623.     rFeedInfo.TMRFM[5]:=rFeedInfo.TMRFM[1];
  2624.     rFeedInfo.TMRFM[4]:=rFeedInfo.TMRFM[1];
  2625.     end;
  2626.  
  2627.   //recalculate pemNDF for use in analysis of bcp files
  2628.   pemNDF[1]:=0;
  2629.   TotalDM:=0;
  2630.   for counter := 0 to rFeedInfo.iNoFeeds-1 do
  2631.    begin
  2632.    pemNDF[1]:=pemNDF[1]+rFeedInfo.TMRFeed[counter].pemNDF*StrToFloat(FeedOrder[counter,8]);
  2633.    TotalDM:=TotalDM+StrToFloat(FeedOrder[counter,8]);
  2634.    end;
  2635.   if TotalDM>0 then pemNDF[1]:=pemNDF[1]/TotalDM else pemNDF[1]:=0;
  2636.   //prepare Feeding array
  2637.   Feeding:=nil;
  2638.   SetLength(Feeding,rFeedInfo.iNoFeeds*5);
  2639.   for counter2:=0 to rFeedInfo.iNoFeeds-1 do
  2640.    for n:=0 to 4 do
  2641.     Feeding[counter2+n*(rFeedInfo.iNoFeeds)]:=StrToFloat(FeedOrder[counter2,8+n])/Thousand;
  2642.  NotAlkapHer:=True;
  2643.  for counter := 0 to rFeedInfo.iNoFeeds-1 do
  2644.   begin
  2645.   if (FeedOrder[counter,2]='AlkabupHa') and (StrToFloat(FeedOrder[counter,3])>0)
  2646.       then
  2647.    begin
  2648.    NotAlkapHer:=False;
  2649.    AlkabupHaCounter:=counter;
  2650. //AlkabupHa contains 93 moles NH3 per kg
  2651.    if TAcidEaten>0 then
  2652.     AcidNeutralised:=(TAcidEaten-StrToFloat(FeedOrder[counter,3])*93)/TAcidEaten;
  2653.    if AcidNeutralised<0 then AcidNeutralised:=0;
  2654.    end;
  2655.   end;
  2656.  TimeToFinish:=Round(LactationLength/DaysInWeek);
  2657.  if (rFeedInfo.DietToFed[4]) and (rFeedInfo.DietToFed[5]) then
  2658.   TimeToFinish:=Round(LactationLength/DaysInWeek)+Animal.FarOff+Animal.CloseTo
  2659.  else if (rFeedInfo.DietToFed[4]) then
  2660.   TimeToFinish:=Round(LactationLength/DaysInWeek)+Animal.FarOff
  2661.  else if (rFeedInfo.DietToFed[5]) then
  2662.   TimeToFinish:=Round(LactationLength/DaysInWeek)+Animal.CloseTo;
  2663.  if SingleRun then
  2664.   begin
  2665.   if Beef then
  2666.    begin
  2667.    TimeToStart:=1;
  2668.    TimeToFinish:=1;
  2669.    end
  2670.   else
  2671.    begin
  2672.    if LeftStr(Instant.Edit66.Text,1)='-' then
  2673.     begin
  2674.     TimeToStart:=Round(LactationLength/DaysInWeek)+7
  2675.                  +StrToInt(Instant.Edit66.Text);
  2676.     TimeToFinish:=TimeToStart;
  2677.     end
  2678.    else
  2679.     begin
  2680.     TimeToStart:=StrToInt(Instant.Edit66.Text);
  2681.     TimeToFinish:=StrToInt(Instant.Edit66.Text);
  2682.     end;
  2683.    end;
  2684.   if TimeToStart>Round(LactationLength/DaysInWeek) then
  2685.    begin
  2686.    rFeedInfo.DietToFed[1]:=False;
  2687.    if Round(LactationLength/DaysInWeek)+Animal.FarOff>TimeToStart then
  2688.     rFeedInfo.DietToFed[4]:=True
  2689.    else
  2690.     rFeedInfo.DietToFed[5]:=True;
  2691.    end;
  2692.   end
  2693.  else
  2694.   TimeToStart:=1;
  2695. WhyWontItWork:=2;
  2696.  for YearOfLactation:=1 to 3 do
  2697.   if LactationNo[YearOfLactation]>0 then
  2698.    begin
  2699.    CowParity:=YearOfLactation-1;
  2700.    if SingleRun then
  2701.     begin
  2702.     rFeedInfo.RumFillUpper:=0.9;
  2703.     if DryCow then
  2704.      rFeedInfo.RumFillUpper:=0.8;
  2705.  
  2706.     if Beef then
  2707.      rFeedInfo.Weight:=StrToFloat(Instant.Edit66.Text)/kgToOther
  2708.     else
  2709.      rFeedInfo.Weight:=StrToFloat(Instant.Edit61.Text)/kgToOther;
  2710.     if LeftStr(Instant.Edit66.Text,1)<>'-' then
  2711.      Animal.Weight:=Round(rFeedInfo.Weight);
  2712.     rFeedInfo.CS:=StrToFloat(Instant.Edit62.Text);
  2713. //    Mature(Round(StrtoInt(Instant.Edit61.Text)/kgToOther),StrtoFloat(Instant.Edit62.Text));
  2714.     CS:=StrToFloat(Instant.Edit62.Text);
  2715.     end
  2716.    else
  2717.     begin
  2718.     rFeedInfo.RumFillUpper:=0.7;
  2719. //    rFeedInfo.Weight:=StrToFloat(CowF.Edit1.Text)/kgToOther;
  2720. //    Animal.Weight:=Round(rFeedInfo.Weight);
  2721. //    rFeedInfo.CS:=StrToFloat(CowF.Edit2.Text);
  2722. //    Mature(Round(StrtoInt(CowF.Edit1.Text)/kgToOther),StrtoFloat(CowF.Edit2.Text));
  2723. //    CS:=rFeedInfo.CalvCS[YearOfLactation];
  2724.     end;
  2725.    ParityEffects(YearOfLactation,Round(rFeedInfo.MY305d[YearOfLactation]/kgToOther),
  2726.              StrtoFloat('4'),Strtofloat('3.3'));
  2727.    rFeedInfo.CalvWeight[YearOfLactation]:=Round(CalcLwtFromCSandP/kgToOther);
  2728.    AnimalLipid:=LipidParity;
  2729. //   if CowF.CheckBox1.Checked=True then
  2730.     CalcCSandGrowth(0,rFeedInfo.Mated[YearOfLactation]*7,YearOfLactation,CS,
  2731.                     MatProtein,ProteinWt);
  2732. //   else
  2733. //    CalcCSandGrowth(0,360,YearOfLactation,CS,MatProtein,ProteinWt);
  2734. //ProteinWt gives the weight of protein of animal. Transferred to BodyProtein
  2735.    BodyProtein:=ProteinWt;
  2736.    BodyProteinLoss:=0;
  2737.    if SingleRun then rFeedInfo.MaxMY:=StrToFloat(Instant.Edit63.Text)/kgToOther
  2738.    else
  2739.     if YearOfLactation=1 then
  2740.      rFeedInfo.MaxMY:=CalcMY(0.00465*rFeedInfo.MY305d[1],0.00218,45,0)
  2741.     else if YearOfLactation=2 then
  2742.      rFeedInfo.MaxMY:=CalcMY(0.005317*rFeedInfo.MY305d[2],0.00322,35,0)
  2743.     else
  2744.      rFeedInfo.MaxMY:=CalcMY(0.005877*rFeedInfo.MY305d[3],0.00393,35,0);
  2745.  for WeekOfLactation:=TimeToStart to TimeToFinish do
  2746.   begin
  2747. //work out what diet to be fed
  2748.   {PBar:=PBar+1; }
  2749.   if Beef then BodyComposition(ptrAnimal,2,WeekOfLactation-1);
  2750.   rFeedInfo.Week:=WeekOfLactation-1;
  2751.   if WeekOfLactation-1<rFeedInfo.WeekToEnd[1] then rFeedInfo.Diet:=1
  2752.   else if WeekOfLactation-1<rFeedInfo.WeekToEnd[2] then rFeedInfo.Diet:=2
  2753.   else if WeekOfLactation-1<Round(LactationLength/7) then rFeedInfo.Diet:=3
  2754. //but if no diet5, then rFeedInfo.Diet should = 4
  2755.   else if rFeedInfo.DietToFed[5] then
  2756.    begin
  2757.    if WeekOfLactation-1<TimeToFinish-3 then rFeedInfo.Diet:=4 else rFeedInfo.Diet:=5;
  2758.    end
  2759.   else rFeedInfo.Diet:=4;
  2760.   if LeftStr(Instant.Edit66.Text,1)='-' then
  2761.    begin
  2762.    if Round(LactationLength/DaysInWeek)+Animal.FarOff>TimeToStart then
  2763.     begin
  2764.     rFeedInfo.Diet:=4;
  2765.     pemNDF[4]:=pemNDF[1];
  2766.     for counter2:=0 to rFeedInfo.iNoFeeds-1 do
  2767.      Feeding[counter2+(rFeedInfo.Diet-1)*(rFeedInfo.iNoFeeds)]:=
  2768.                  StrToFloat(FeedOrder[counter2,8])/Thousand;
  2769.     for n:=1 to rFeedInfo.iNoFeeds do
  2770.      FeedOrder[n-1,7+rFeedInfo.Diet]:=FeedOrder[n-1,7+1];
  2771.     end
  2772.    else
  2773.     begin
  2774.     rFeedInfo.Diet:=5;
  2775.     pemNDF[5]:=pemNDF[1];
  2776.     for counter2:=0 to rFeedInfo.iNoFeeds-1 do
  2777.      Feeding[counter2+(rFeedInfo.Diet-1)*(rFeedInfo.iNoFeeds)]:=
  2778.                  StrToFloat(FeedOrder[counter2,8])/Thousand;
  2779.     for n:=1 to rFeedInfo.iNoFeeds do
  2780.      FeedOrder[n-1,7+rFeedInfo.Diet]:=FeedOrder[n-1,7+1];
  2781.     end;
  2782.    end;
  2783.  
  2784.   if WeekOfLactation-1<=rFeedInfo.ParlourWeeks[1] then rFeedInfo.Parlour:=1
  2785.   else if WeekOfLactation-1<=rFeedInfo.ParlourWeeks[2] then rFeedInfo.Parlour:=2
  2786.   else if WeekOfLactation-1<=rFeedInfo.ParlourWeeks[3] then rFeedInfo.Parlour:=3
  2787.   else if WeekOfLactation-1<=rFeedInfo.ParlourWeeks[4] then rFeedInfo.Parlour:=4;
  2788. //Eating Time
  2789.   AwakeTime:=[1..24];
  2790.   FSGrazingpemNDF:=False;
  2791.   if FSGrazingAll[rFeedInfo.Diet] then
  2792.    begin
  2793.    pemNDF[rFeedInfo.Diet]:=rFeedInfo.GrazingFeed.pemNDF;
  2794.    ActiveFibreTMR:=pemNDF[rFeedInfo.Diet];
  2795.    ActiveFibreGrazing:=ActiveFibreTMR;
  2796.    FSGrazingpemNDF:=True;
  2797.    end
  2798.   else if FSGrazing[rFeedInfo.Diet] then
  2799.    begin
  2800.    FSGrazingpemNDF:=True;
  2801.    ActiveFibreGrazing:=rFeedInfo.GrazingFeed.pemNDF;
  2802.    ActiveFibreTMR:=pemNDF[rFeedInfo.Diet];
  2803.    end
  2804.   else
  2805.    ActiveFibreTMR:=pemNDF[rFeedInfo.Diet];
  2806.   if pemNDF[rFeedInfo.Diet]<27.5 then
  2807.    RuminatingTime:=0.0054*pemNDF[rFeedInfo.Diet]+0.4531
  2808.   else
  2809.    RuminatingTime:=0.6;
  2810.   Available2Eat:=WakingTime*(1-RuminatingTime);
  2811. //  if Available2Eat<9.5 then EatingTime:=[4,7,9,12,15,18,21,24]
  2812. //  else if Available2Eat<10.5 then EatingTime:=[3,6,9,12,14,16,18,21,24]
  2813. //  else if Available2Eat<11.5 then EatingTime:=[2,4,6,9,12,14,16,18,21,23]
  2814. //  else EatingTime:=[2,4,6,8,10,12,14,16,18,21,23];
  2815. //if TMRRobotic alter ParlourFeeds and ParlourHour
  2816.   if TMRRobotic then
  2817.    begin
  2818.    if (SingleRun) then
  2819.     begin
  2820. //    ParlourFeeds[rFeedInfo.Parlour]:=2;
  2821. //    ParlourHour[rFeedInfo.Parlour]:=[5,16];
  2822.     RoboticFeeds[rFeedInfo.Parlour]:=trunc(StrToFloat(Instant.Edit63.Text)/RoboticsYield*20);
  2823.     text:=FloatToStrF(RoboticFeeds[rFeedInfo.Parlour]/10,ffFixed,3,0);
  2824.     RoboticFeeds[rFeedInfo.Parlour]:=StrToFloat(text)/2;
  2825.     if RightStr(FloatToStr(RoboticFeeds[rFeedInfo.Parlour]),2)='.5' then
  2826.      begin
  2827.      HalfRobotic:=True;
  2828.      end
  2829.     else
  2830.      begin
  2831.      HalfRobotic:=False;
  2832.      end;
  2833.     if RoboticFeeds[rFeedInfo.Parlour]<2.4 then
  2834.      begin
  2835.      RoboticHour[rFeedInfo.Parlour]:=[1,12];
  2836.      if Instant.RadioButton4.Checked then EatingTime:=[3,8,11,14,17,19,23]
  2837.      else if Instant.RadioButton6.Checked then EatingTime:=[3,8,14,17,19,23]
  2838.      else if Instant.RadioButton7.Checked then EatingTime:=[3,8,14,23];
  2839.      end
  2840.     else if RoboticFeeds[rFeedInfo.Parlour]<3.4 then
  2841.      begin
  2842.      RoboticHour[rFeedInfo.Parlour]:=[1,8,16];
  2843.      if Instant.RadioButton4.Checked then EatingTime:=[3,5,9,11,14,17,19,23]
  2844.      else if Instant.RadioButton6.Checked then EatingTime:=[3,9,14,17,19,23]
  2845.      else if Instant.RadioButton7.Checked then EatingTime:=[3,9,14,23];
  2846.      end
  2847.     else if RoboticFeeds[rFeedInfo.Parlour]<4.4 then
  2848.      begin
  2849.      RoboticHour[rFeedInfo.Parlour]:=[1,6,12,18];
  2850.      if Instant.RadioButton4.Checked then EatingTime:=[3,5,9,11,14,17,19,23]
  2851.      else if Instant.RadioButton6.Checked then EatingTime:=[3,9,14,17,19,23]
  2852.      else if Instant.RadioButton7.Checked then EatingTime:=[3,9,14,23];
  2853.      end
  2854.     else
  2855.      begin
  2856.      RoboticHour[rFeedInfo.Parlour]:=[1,5,10,15,20];
  2857.      if Instant.RadioButton4.Checked then EatingTime:=[3,6,9,11,14,17,19,23]
  2858.      else if Instant.RadioButton6.Checked then EatingTime:=[3,9,14,17,19,23]
  2859.      else if Instant.RadioButton7.Checked then EatingTime:=[3,9,14,23];
  2860.      end;
  2861.     ParlourHour[1]:=[];
  2862. //    RoboticHour[rFeedInfo.Parlour]:=[5,16];
  2863.     if (FSGrazing[1]) or (FSGrazingAll[1]) then
  2864.      GrazingHour[1]:=GrazingHour[1]-RoboticHour[1];
  2865.     end
  2866.    else if WeekOfLactation=1 then
  2867.     begin
  2868.     ParlourFeeds[rFeedInfo.Parlour]:=2;
  2869.     ParlourHour[rFeedInfo.Parlour]:=[5,16];
  2870.     end
  2871.    else if rNutrientsAbsorbed.MilkFromE[CowParity,WeekOfLactation-2]<=2*RoboticsYield then
  2872.     begin
  2873.     ParlourFeeds[rFeedInfo.Parlour]:=2;
  2874.     ParlourHour[rFeedInfo.Parlour]:=[5,16];
  2875.     end
  2876.    else if rNutrientsAbsorbed.MilkFromE[CowParity,WeekOfLactation-2]<=3*RoboticsYield then
  2877.     begin
  2878.     ParlourFeeds[rFeedInfo.Parlour]:=3;
  2879.     ParlourHour[rFeedInfo.Parlour]:=[5,13,20];
  2880.     end
  2881.    else if rNutrientsAbsorbed.MilkFromE[CowParity,WeekOfLactation-2]<=4*RoboticsYield then
  2882.     begin
  2883.     ParlourFeeds[rFeedInfo.Parlour]:=4;
  2884.     ParlourHour[rFeedInfo.Parlour]:=[5,11,17,22];
  2885.     end
  2886.    else
  2887.     begin
  2888.     ParlourFeeds[rFeedInfo.Parlour]:=5;
  2889.     ParlourHour[rFeedInfo.Parlour]:=[5,8,13,19,24];
  2890.     end;
  2891.    end;
  2892. //Work out Parlour Feed to be fed
  2893.   if TMRRobotic then
  2894.    begin
  2895.    rFeedInfo.RoboticPerMeal1:=StrToFloat(FeedingStrategy.Edit9.Text)
  2896.                                /kgToOther/RoboticFeeds[rFeedInfo.Parlour];
  2897.    if SingleRun then LactationDay1:=StrToFloat(Instant.Edit63.Text)/kgToOther;
  2898.    PF:=(LactationDay1-StrToFloat(FeedingStrategy.Edit17.Text)/kgToOther)
  2899.            *StrToFloat(FeedingStrategy.Edit13.Text);
  2900.    if PF>(StrToFloat(FeedingStrategy.Edit21.Text)
  2901.              -StrToFloat(FeedingStrategy.Edit17.Text))/kgToOther
  2902.              *StrToFloat(FeedingStrategy.Edit13.Text) then
  2903.     PF:=(StrToFloat(FeedingStrategy.Edit21.Text)
  2904.             -StrToFloat(FeedingStrategy.Edit17.Text))/kgToOther
  2905.             *StrToFloat(FeedingStrategy.Edit13.Text);
  2906.    if PF<0 then PF:=0;
  2907.    rFeedInfo.RoboticPerMeal2:=PF/RoboticFeeds[rFeedInfo.Parlour];
  2908.    end
  2909.   else if (FSParlour[rFeedInfo.Diet]) and (rFeedInfo.Diet<>4) and (rFeedInfo.Diet<>5) then
  2910.    if WeekOfLactation<=rFeedInfo.ParlourWeeks[1] then
  2911.     if Fixed_MilkConcentrate[1] then
  2912.      rFeedInfo.ParlourPerMeal:=StrToFloat(FeedingStrategy.Edit9.Text)
  2913.                                /kgToOther/ParlourFeeds[rFeedInfo.Parlour]
  2914.      else
  2915.      begin
  2916.      if WeekOfLactation=1 then
  2917.       begin
  2918.       if SingleRun then LactationDay1:=StrToFloat(Instant.Edit63.Text)/kgToOther;
  2919.       PF:=(LactationDay1-StrToFloat(FeedingStrategy.Edit17.Text)/kgToOther)
  2920.            *StrToFloat(FeedingStrategy.Edit13.Text);
  2921.       if PF>(StrToFloat(FeedingStrategy.Edit21.Text)
  2922.              -StrToFloat(FeedingStrategy.Edit17.Text))/kgToOther
  2923.              *StrToFloat(FeedingStrategy.Edit13.Text) then
  2924.        PF:=(StrToFloat(FeedingStrategy.Edit21.Text)
  2925.             -StrToFloat(FeedingStrategy.Edit17.Text))/kgToOther
  2926.             *StrToFloat(FeedingStrategy.Edit13.Text);
  2927.       if PF<0 then PF:=0;
  2928.       if FeedingStrategy.Edit9.Enabled then
  2929.        PF:=PF+StrToFloat(FeedingStrategy.Edit9.Text)/kgToOther;
  2930.       rFeedInfo.ParlourPerMeal:=PF/ParlourFeeds[rFeedInfo.Parlour];
  2931.       end
  2932.      else
  2933.       begin
  2934.       if SingleRun then
  2935.        PF:=(StrToFloat(Instant.Edit63.Text)/kgToOther
  2936.             -StrToFloat(FeedingStrategy.Edit17.Text)/kgToOther)
  2937.             *StrToFloat(FeedingStrategy.Edit13.Text)
  2938.       else
  2939.        PF:=(rNutrientsAbsorbed.MilkFromE[CowParity,WeekOfLactation-2]
  2940.             -StrToFloat(FeedingStrategy.Edit17.Text)/kgToOther)
  2941.             *StrToFloat(FeedingStrategy.Edit13.Text);
  2942.       if PF>(StrToFloat(FeedingStrategy.Edit21.Text)
  2943.              -StrToFloat(FeedingStrategy.Edit17.Text))/kgToOther
  2944.              *StrToFloat(FeedingStrategy.Edit13.Text) then
  2945.        PF:=(StrToFloat(FeedingStrategy.Edit21.Text)
  2946.             -StrToFloat(FeedingStrategy.Edit17.Text))/kgToOther
  2947.             *StrToFloat(FeedingStrategy.Edit13.Text);
  2948.       if PF<0 then PF:=0;
  2949.       if FeedingStrategy.Edit9.Enabled then
  2950.        PF:=PF+StrToFloat(FeedingStrategy.Edit9.Text)/kgToOther;
  2951.       rFeedInfo.ParlourPerMeal:=PF/ParlourFeeds[rFeedInfo.Parlour];
  2952.       end;
  2953.       end;
  2954.   if TMRRobotic then
  2955.    begin
  2956.    if rFeedInfo.RoboticPerMeal1>MaxParlourPerMeal then
  2957.     rFeedInfo.RoboticPerMeal1:=MaxParlourPerMeal;
  2958.    rFeedInfo.RoboticPerMeal1:=rFeedInfo.RoboticPerMeal1
  2959.                             *ParlourTotalDM[rFeedInfo.Parlour]/100;
  2960.    if rFeedInfo.RoboticPerMeal2>MaxParlourPerMeal then
  2961.     rFeedInfo.RoboticPerMeal2:=MaxParlourPerMeal;
  2962.    rFeedInfo.RoboticPerMeal2:=rFeedInfo.RoboticPerMeal2
  2963.                             *RoboticTotalDM2[rFeedInfo.Parlour]/100;
  2964.    rFeedInfo.LiquidPerMeal:=0.5/kgToOther/RoboticFeeds[rFeedInfo.Parlour]
  2965.                             *rFeedInfo.LiquidFeed.DM/100;
  2966.    end
  2967.   else
  2968.    begin
  2969.    if rFeedInfo.ParlourPerMeal>MaxParlourPerMeal then
  2970.     rFeedInfo.ParlourPerMeal:=MaxParlourPerMeal;
  2971.    rFeedInfo.ParlourPerMeal:=rFeedInfo.ParlourPerMeal
  2972.                             *ParlourTotalDM[rFeedInfo.Parlour]/100;
  2973.    end;
  2974.   if SingleRun then LactationDay1:=StrToFloat(Instant.Edit63.Text)/kgToOther;
  2975.   Conceptus(WeekOfLactation*7,rFeedInfo.Mated[YearOfLactation]*7);//ConcepDay
  2976.   if LeftStr(Instant.Edit66.Text,1)<>'-' then
  2977.    CalcCSandGrowth(WeekOfLactation*7,rFeedInfo.Mated[YearOfLactation]*7,
  2978.                   YearOfLactation,rFeedInfo.CalvCS[YearOfLactation],
  2979.                   MatProtein,ProteinWt);
  2980.   if (WeekOfLactation=1) or (CowParity=2) then BdyWt:=0
  2981.    else BdyWt:=rNutrientsAbsorbed.BodyWeight[CowParity,WeekOfLactation-2];
  2982.   if {(YearOfLactation=3) and} (WeekOfLactation=1) then
  2983.       rNutrientsAbsorbed.DMI[CowParity,WeekOfLactation+1]:=0;
  2984.   CalcEEReq(WeekOfLactation,CowParity,LactationLength,ptrNutAbsorbed,ptrAnimal);
  2985. {Actual Weight is the lipid free empty body weight of the animal, divided by the
  2986. lipid free empty body weight of the chosen mature animal multiplied by the weight
  2987. of the animal calculated at condition score of 2.5. It is used to calculate maximum
  2988. intake and also to calculate rumen volume }
  2989.   if Beef then
  2990.    begin
  2991.    if BeefCorrection then
  2992.     rFeedInfo.ActualWeight:=Animal.LipidFreeEmptyBody/Animal.MatureLFEB
  2993.                                               *Animal.WeightAt2Point5
  2994.    else
  2995.     rFeedInfo.ActualWeight:=Animal.WeightArray[CowParity,WeekOfLactation-1];
  2996.    end
  2997.   else
  2998.    rFeedInfo.ActualWeight:=Animal.LFEB/Animal.MatureLFEB*Animal.WeightAt2Point5;
  2999. //  rFeedInfo.ActualWeight:=675;
  3000. {MaxIntakePerHour: the maximum amount that can be eaten per hour based on Active
  3001. Fibre content of the intake (see Bioparamilk\v1.6 against v1.8\Active fibre vs
  3002. intake rate.xls). As well as Active Fibre influencing intake, the size of the animal
  3003. also does.}
  3004.   if Beef then
  3005.    rFeedInfo.MaxIntakePerHourAF10:=power(10,((log10(10)-0.5314)
  3006.        *-0.9154)+1.0792)*power(rFeedInfo.ActualWeight,0.73)/power(650,0.73)
  3007.        *power(rFeedInfo.ActualWeight/Animal.WeightAt2Point5,0.86)
  3008.   else
  3009.    rFeedInfo.MaxIntakePerHourAF10:=power(10,((log10(10)-0.5314)
  3010.        *-0.9154)+1.0792)*power(rFeedInfo.ActualWeight,0.73)/power(650,0.73);
  3011.   if rFeedInfo.DietToFed[rFeedInfo.Diet] then
  3012.    begin
  3013.    if Beef then
  3014.     rFeedInfo.MaxIntakePerHour:=power(10,((log10(pemNDF[rFeedInfo.Diet])-0.5314)
  3015.        *-0.9154)+1.0792)*power(rFeedInfo.ActualWeight,0.73)/power(650,0.73)
  3016.        *power(rFeedInfo.ActualWeight/Animal.WeightAt2Point5,0.86)
  3017.    else if YearOfLactation=3 then
  3018.     rFeedInfo.MaxIntakePerHour:=power(10,((log10(pemNDF[rFeedInfo.Diet])-0.5314)
  3019.        *-0.9154)+1.0792)*power(rFeedInfo.ActualWeight,0.73)/power(650,0.73)
  3020.    else
  3021.     rFeedInfo.MaxIntakePerHour:=power(10,((log10(pemNDF[rFeedInfo.Diet])-0.5314)
  3022.        *-0.9154)+1.0792)*power(rFeedInfo.ActualWeight,0.73)/power(650,0.73)
  3023.        *power(rFeedInfo.ActualWeight/Animal.WeightAt2Point5,0.86);
  3024.    rFeedInfo.MaxIntakePerHour:=0.85*rFeedInfo.MaxIntakePerHour;  //0.75
  3025.    if LeftStr(Instant.Edit66.Text,1)='-' then rFeedInfo.MaxIntakePerHour:=1.25*rFeedInfo.MaxIntakePerHour;
  3026.    if FSGrazingpemNDF then
  3027.     begin
  3028.     if YearOfLactation=3 then
  3029.      rFeedInfo.MaxIntakePerHourPGrazing:=power(10,((log10(ActiveFibreGrazing)-0.5314)
  3030.        *-0.9154)+1.0792)*power(rFeedInfo.ActualWeight,0.73)/power(650,0.73)
  3031.     else
  3032.      rFeedInfo.MaxIntakePerHourPGrazing:=power(10,((log10(ActiveFibreGrazing)-0.5314)
  3033.        *-0.9154)+1.0792)*power(rFeedInfo.ActualWeight,0.73)/power(650,0.73)
  3034.        *power(rFeedInfo.ActualWeight/Animal.WeightAt2Point5,0.86);
  3035. // put MaxIntakePerHourPGrazing down by 0.75 to match MaxIntakePerHour
  3036.     rFeedInfo.MaxIntakePerHourPGrazing:=0.75*rFeedInfo.MaxIntakePerHourPGrazing;
  3037.     if LeftStr(Instant.Edit66.Text,1)='-' then
  3038.      rFeedInfo.MaxIntakePerHourPGrazing:=1.25*rFeedInfo.MaxIntakePerHourPGrazing;
  3039.     end;
  3040.    end;
  3041. //Bert Tolkamp reckons that for example if the cow has locomotion problems and
  3042. //intake is reduced, the cow is able to eat at a quicker rate - up to 3x.
  3043. //L. A. Gonza´ lez, B. J. Tolkamp, M. P. Coffey, A. Ferret, and I. Kyriazakis
  3044. //Changes in Feeding Behavior as Possible Indicators for the Automatic
  3045. //Monitoring of Health Disorders in Dairy Cows J. Dairy Sci. 91:1017–1028, 2008
  3046. //Auto sets NoOfMeals to  7!
  3047.   if NoOfMeals<11 then
  3048.    begin
  3049.    rFeedInfo.MaxIntakePerHour:=rFeedInfo.MaxIntakePerHour*(10-NoOfMeals);
  3050.    rFeedInfo.MaxIntakePerHourPGrazing:=rFeedInfo.MaxIntakePerHourPGrazing*(10-NoOfMeals);
  3051.    end
  3052.   else
  3053.    begin
  3054.    rFeedInfo.MaxIntakePerHour:=rFeedInfo.MaxIntakePerHour*(10-7);
  3055.    rFeedInfo.MaxIntakePerHourPGrazing:=rFeedInfo.MaxIntakePerHourPGrazing*(10-7);
  3056.    end;
  3057. WhyWontItWork:=3;
  3058.   if (rFeedInfo.DietToFed[1]) and (WeekOfLactation<=rFeedInfo.WeekToEnd[1])
  3059.    and (HerdProbsS[YearOfLactation-1,0]>0) then
  3060.    begin
  3061.    rFeedInfo.FourOrFive:=False;
  3062.    IfDietTrue(WeekOfLactation,Lignin,MatProtein);
  3063.    end
  3064.   else if (rFeedInfo.DietToFed[2]) and (WeekOfLactation>rFeedInfo.WeekToEnd[1])
  3065.    and (WeekOfLactation<=rFeedInfo.WeekToEnd[2]) and (HerdProbsS[YearOfLactation-1,1]>0) then
  3066.    begin
  3067.    rFeedInfo.FourOrFive:=False;
  3068.    IfDietTrue(WeekOfLactation,Lignin,MatProtein);
  3069.    end
  3070.   else if (rFeedInfo.DietToFed[3]) and (WeekOfLactation>rFeedInfo.WeekToEnd[2])
  3071.    and (WeekOfLactation<=Round(LactationLength/7)) and (HerdProbsS[YearOfLactation-1,2]>0) then
  3072.    begin
  3073.    rFeedInfo.FourOrFive:=False;
  3074.    IfDietTrue(WeekOfLactation,Lignin,MatProtein);
  3075.    end
  3076. //take out and (WeekOfLactation<=TimeToFinish-3) ??
  3077.   else if (rFeedInfo.DietToFed[4]) and (WeekOfLactation>Round(LactationLength/7))
  3078.    {and (WeekOfLactation<=TimeToFinish-3)} and (HerdProbsS[YearOfLactation-1,3]>0) then
  3079.    begin
  3080.    rFeedInfo.FourOrFive:=True;
  3081.    rFeedInfo.ParlourPerMeal:=0;
  3082.    rFeedInfo.RumFillUpper:=rFeedInfo.RumFillUpper*0.95;
  3083.    IfDietTrue(WeekOfLactation,Lignin,MatProtein);
  3084.    end
  3085.   else if (rFeedInfo.DietToFed[5]) and (WeekOfLactation>TimeToFinish-3)
  3086.    and (WeekOfLactation<=TimeToFinish) and (HerdProbsS[YearOfLactation-1,4]>0) then
  3087.    begin
  3088.    rFeedInfo.FourOrFive:=True;
  3089.    rFeedInfo.ParlourPerMeal:=0;
  3090.    rFeedInfo.RumFillUpper:=rFeedInfo.RumFillUpper*0.95;
  3091.    IfDietTrue(WeekOfLactation,Lignin,MatProtein);
  3092.    end
  3093.   else
  3094.    begin
  3095.    rNutrientsAbsorbed.DMI[CowParity,WeekOfLactation-1]:=0;
  3096.    rNutrientsAbsorbed.EESupplied[CowParity,WeekOfLactation-1]:=0;
  3097.    rNutrientsAbsorbed.DietME[CowParity,WeekOfLactation-1]:=0;
  3098.    rNutrientsAbsorbed.MilkFromE[CowParity,WeekOfLactation-1]:=0;
  3099.    rNutrientsAbsorbed.MilkFromP[CowParity,WeekOfLactation-1]:=0;
  3100.    rNutrientsAbsorbed.MPMaint[CowParity,WeekOfLactation-1]:=0;
  3101.    rNutrientsAbsorbed.MEMaint[CowParity,WeekOfLactation-1]:=0;
  3102.    rNutrientsAbsorbed.pHav[CowParity,WeekOfLactation-1]:=0;
  3103.    rNutrientsAbsorbed.ParlourDMI[CowParity,WeekOfLactation-1]:=0;
  3104.    rNutrientsAbsorbed.ProteinToEnergy[CowParity,WeekOfLactation-1]:=0;
  3105.    end;
  3106.   if rNutrientsAbsorbed.MilkFromP[CowParity,WeekOfLactation-1]<0 then
  3107.    rNutrientsAbsorbed.MilkFromP[CowParity,WeekOfLactation-1]:=0;
  3108. //BodyChange is individual time point and BodyWeight is accumalation of BodyChange
  3109.   AnimalLipid:=AnimalLipid+deltaL*1.07*7;
  3110.   rNutrientsAbsorbed.BodyChange[CowParity,WeekOfLactation-1]:=
  3111.                              deltaL*1.07+(deltaP-ProteinLoss)*4;//LostProtein
  3112.   if WeekOfLactation=1 then
  3113.    rNutrientsAbsorbed.BodyWeight[CowParity,weekOfLactation-1]:=0
  3114.   else
  3115.    rNutrientsAbsorbed.BodyWeight[CowParity,WeekOfLactation-1]:=
  3116.                      rNutrientsAbsorbed.BodyWeight[CowParity,WeekOfLactation-2]
  3117.                      +rNutrientsAbsorbed.BodyChange[CowParity,WeekOfLactation-1]*7;
  3118.   rNutrientsAbsorbed.EESupplied[CowParity,WeekOfLactation-1]:=
  3119.    rNutrientsAbsorbed.DietME[CowParity,WeekOfLactation-1]
  3120.    *rNutrientsAbsorbed.DMI[CowParity,WeekOfLactation-1];
  3121. //  if not SingleRun then ProgressBar1.Position:=Round(PBar/PBarCount*100);
  3122.   if (Beef) and (not SingleRun) then
  3123.    begin
  3124.    rNutrientsAbsorbed.PotentialMilk[CowParity,WeekOfLactation-1]:=
  3125.           Animal.WeightArray[CowParity,WeekOfLactation-1]/10;
  3126.    rNutrientsAbsorbed.MilkFromE[CowParity,WeekOfLactation-1]:=
  3127.            Animal.Protein[CowParity,WeekOfLactation-1]/2;
  3128.    rNutrientsAbsorbed.MilkFromP[CowParity,WeekOfLactation-1]:=
  3129.            Animal.Lipid[CowParity,WeekOfLactation-1]/2;
  3130.    rNutrientsAbsorbed.ParlourDMI[CowParity,WeekOfLactation-1]:=
  3131.            Animal.CS[CowParity,WeekOfLactation-1]*10;
  3132.    end;
  3133.   end; //of for WeekOfLactation
  3134.   end; //of if LactationNo[YearOfLactation]>0 then
  3135. //ProgressBar1.Position:=0;
  3136. //if not Sheep then Report.Visible:=True;
  3137. //Finish:=GetTickCount;
  3138. //Results.Label24.Caption:=IntToStr(Finish-Start);
  3139. //WhyWontItWork:=4;
  3140. SpeedButton6.Enabled:=True;
  3141. SpeedButton7.Enabled:=True;
  3142. SpeedButton8.Enabled:=True;
  3143. SpeedButton10.Enabled:=True;
  3144. RumenRaftFactor:=0;
  3145. for n := 1 to 24 do
  3146.  RumenRaftFactor:=RumenRaftFactor+UNDFForage[n];
  3147. RumenRaftFactor:=RumenRaftFactor/24;
  3148. SpeedButton6.Click;  //Results
  3149. SpeedButton6.Down:=True;
  3150. if WhatIfBoolean then WhatIfForm.Show;
  3151. //save output
  3152. if DietTrue then Welcome.SaveFormulation;
  3153. SpeedButton7Click(Main);  //Save
  3154. AutoCreatePreMix1.Enabled:=True;
  3155. finally
  3156. NotRunYet:=False; RunpH6:=False;
  3157. if not Administrator then
  3158.  begin
  3159.  DBNotConnected:=1;
  3160.  SavingResults:=True;
  3161.  SaveFormulations;
  3162.  EnDecryptFile(DatabaseDirectory+'\DBFormulation.ph6');
  3163.  SavePreMixes;
  3164.  EnDecryptFile(DatabaseDirectory+'\DBPreMixes.ph6');
  3165.  SaveResults;
  3166.  FormulationHigh:=Length(DBFormulation);
  3167.  PreMixFeedsHigh:=Length(DBPreMixes);
  3168.  WriteIniFile;
  3169.  DBNotConnected:=0;
  3170.  end;
  3171. RunpH6:=True;
  3172. Screen.Cursor:=SaveCursor;
  3173. end;//try
  3174. end;//of if not CanRun which means DM is zero on something
  3175. end;
  3176.  
  3177. procedure TMain.IfDietTrue(WeekOfLactation: Integer;Lignin,MatProtein: Single);
  3178. var
  3179. n,WofLSt: Integer;
  3180. ProportionRumVol: Single;
  3181.  
  3182. begin
  3183. WofLSt:=0;
  3184. ptrAnimal:=@Animal;
  3185. rFeedInfo.EReq:=rNutrientsAbsorbed.EReq[CowParity,WeekOfLactation-1];
  3186. if ChopLength then ProportionRumVol:=0.175 else ProportionRumVol:=0.165;
  3187. if Beef or Sheep then
  3188.  begin
  3189.   rFeedInfo.RVol:=rFeedInfo.ActualWeight*0.165*JerseyOpt;
  3190.  end
  3191. else
  3192.  begin
  3193.  if rFeedInfo.FourOrFive then
  3194.   begin
  3195.   WofLSt:=WeekOfLactation-43;
  3196.   rFeedInfo.RVol:=rFeedInfo.ActualWeight*JerseyOpt*(0.15-0.025/7*WofLSt);
  3197.   end
  3198.  else
  3199.   begin
  3200.   rFeedInfo.RVol:=rFeedInfo.ActualWeight*ProportionRumVol*JerseyOpt;//0.165*(0.5+0.5*(1-exp(-0.0899*(WeekOfLactation-1)*7)));
  3201.   end;
  3202.  end;
  3203. rFeedInfo.RumSA:=251360*power(rFeedInfo.RVol/4189.333,0.667);// 'cm2
  3204. rFeedInfo.RLoad:=rFeedInfo.RVol*0.15;
  3205. rFeedInfo.PPass:=ParticlePassagePpn*1.15*(1/0.8)*0.07095/power(rFeedInfo.ActualWeight,0.27)*JerseyOpt;
  3206. rFeedInfo.LongParticleBR:=0.1436*power(CalcLig(rFeedInfo.Diet,DMIDiet1),-0.4572)
  3207.                              *power(rFeedInfo.ActualWeight,-0.27){*ForageDMBelow30Ppn};
  3208. if MicrobesAcidosis then
  3209.  begin
  3210.  if SingleRun then rFeedInfo.MilkWater:=StrToFloat(Instant.Edit63.Text)
  3211.                                         /kgToOther/HoursInDay
  3212.  else
  3213.   if WeekOfLactation=1 then
  3214.    rFeedInfo.MilkWater:=LactationDay1/HoursInDay
  3215.   else
  3216.    rFeedInfo.MilkWater:=rNutrientsAbsorbed.MilkFromE[CowParity,WeekOfLactation-2]/HoursInDay;
  3217.  end;
  3218.   try
  3219.    NutrientSupply(ptrFeedInfo,@Feeding,ptrNutAbsorbed);
  3220.   except
  3221.    on Exception do MessageBeep(0);
  3222.   end;
  3223.   rNutrientsAbsorbed.pHav[CowParity,WeekOfLactation-1]:=0;
  3224.   for n:=0 to 23 do
  3225.    begin
  3226.    rNutrientsAbsorbed.pHav[CowParity,WeekOfLactation-1]:=
  3227.      rNutrientsAbsorbed.pHav[CowParity,WeekOfLactation-1]
  3228.      +rNutrientsAbsorbed.aNutAbsorbedElement[CowParity,WeekOfLactation-1,n].pH;
  3229.    if n=0 then
  3230.     begin
  3231.     rNutrientsAbsorbed.pHmin[CowParity,WeekOfLactation-1]:=
  3232.        rNutrientsAbsorbed.aNutAbsorbedElement[CowParity,WeekOfLactation-1,n].pH;
  3233.     rNutrientsAbsorbed.pHmax[CowParity,WeekOfLactation-1]:=
  3234.        rNutrientsAbsorbed.pHmin[CowParity,WeekOfLactation-1];
  3235.     end;
  3236.    if rNutrientsAbsorbed.aNutAbsorbedElement[CowParity,WeekOfLactation-1,n].pH
  3237.     >rNutrientsAbsorbed.pHmax[CowParity,WeekOfLactation-1] then
  3238.      rNutrientsAbsorbed.pHmax[CowParity,WeekOfLactation-1]:=
  3239.        rNutrientsAbsorbed.aNutAbsorbedElement[CowParity,WeekOfLactation-1,n].pH;
  3240.    if rNutrientsAbsorbed.aNutAbsorbedElement[CowParity,WeekOfLactation-1,n].pH
  3241.     <rNutrientsAbsorbed.pHmin[CowParity,WeekOfLactation-1] then
  3242.      rNutrientsAbsorbed.pHmin[CowParity,WeekOfLactation-1]:=
  3243.        rNutrientsAbsorbed.aNutAbsorbedElement[CowParity,WeekOfLactation-1,n].pH;
  3244.    end;
  3245.   try
  3246.    begin
  3247.    if not FSGrazingAll[rFeedInfo.Diet] then
  3248.     for n:=0 to rFeedInfo.iNoFeeds-1 do
  3249.      rNutrientsAbsorbed.DietME[CowParity,WeekOfLactation-1]:=rNutrientsAbsorbed.DietME[CowParity,WeekOfLactation-1]
  3250.         +rFeedInfo.TMRFeed[n].ME*StrToFloat(FeedOrder[n,7+rFeedInfo.Diet])/Thousand;
  3251.    ParlourME:=0;
  3252.    for n:=0 to rFeedInfo.iParlour-1 do
  3253.      ParlourME:=ParlourME+rFeedInfo.ParlourFeed[n].ME*PMParlourAmount[n]/100;
  3254.    RoboticME:=0;
  3255.    for n:=0 to rFeedInfo.iRobotic-1 do
  3256.      RoboticME:=RoboticME+rFeedInfo.RoboticFeed[n].ME*PMRoboticAmount[n]/100;
  3257.    end
  3258.   except
  3259.    on Exception do MessageBeep(0);
  3260.   end;
  3261.   if CowParity=2 then
  3262.    begin
  3263.    if WeekOfLactation<Animal.Tstar/DaysInWeek then
  3264.     begin
  3265.     ProteinLoss:=rNutrientsAbsorbed.ProteinFromBody[WeekOfLactation-1];
  3266.     BodyProteinLoss:=BodyProteinLoss+ProteinLoss*7;
  3267.     BodyProteinGain:=0;
  3268.     end
  3269.    else
  3270.     begin
  3271.     ProteinLoss:=0;
  3272.     end;
  3273.    end
  3274.   else
  3275.    begin
  3276.    ProteinLoss:=0;
  3277.    BodyProteinLoss:=0;
  3278.    BodyProteinGain:=0;
  3279.    end;
  3280.   try
  3281.   NutrientUse(ptrNutAbsorbed,ptrAnimal,rFeedInfo.CalvWeight[CowParity+1],ProteinLoss,BodyProteinGain,
  3282.               LostProtein,WeekOfLactation,CowParity)
  3283.   except
  3284.    on Exception do MessageBeep(0);
  3285.   end;
  3286.   rNutrientsAbsorbed.pHav[CowParity,WeekOfLactation-1]:=rNutrientsAbsorbed.pHav[CowParity,WeekOfLactation-1]/24;
  3287.   DegradableRatio(rNutrientsAbsorbed.AvQ[CowParity,WeekOfLactation-1],
  3288.                   rNutrientsAbsorbed.AvS[CowParity,WeekOfLactation-1],
  3289.                   rNutrientsAbsorbed.AvR[CowParity,WeekOfLactation-1],
  3290.                   WeekOfLactation-1);
  3291.   if (FSParlour[rFeedInfo.Diet]) or (TMRRobotic) then
  3292.    begin
  3293.    if TMRRobotic then
  3294.     rNutrientsAbsorbed.ParlourDMI[CowParity,WeekOfLactation-1]:=
  3295.                            rFeedInfo.RoboticPerMeal1*RoboticFeeds[rFeedInfo.Parlour]
  3296.    else
  3297.     rNutrientsAbsorbed.ParlourDMI[CowParity,WeekOfLactation-1]:=
  3298.                            rFeedInfo.ParlourPerMeal*ParlourFeeds[rFeedInfo.Parlour];
  3299.    rNutrientsAbsorbed.RoboticDMI[CowParity,WeekOfLactation-1]:=
  3300.                            rFeedInfo.RoboticPerMeal2*RoboticFeeds[rFeedInfo.Parlour];
  3301.    if rFeedInfo.iLiquid=0 then
  3302.     rNutrientsAbsorbed.LiquidDMI[CowParity,WeekOfLactation-1]:=0
  3303.    else
  3304.     rNutrientsAbsorbed.LiquidDMI[CowParity,WeekOfLactation-1]:=
  3305.                            rFeedInfo.LiquidPerMeal*RoboticFeeds[rFeedInfo.Parlour];
  3306.    end
  3307.   else
  3308.    begin
  3309.    rNutrientsAbsorbed.ParlourDMI[CowParity,WeekOfLactation-1]:=0;
  3310.    rNutrientsAbsorbed.RoboticDMI[CowParity,WeekOfLactation-1]:=0;
  3311.    rNutrientsAbsorbed.LiquidDMI[CowParity,WeekOfLactation-1]:=0;
  3312.    end;
  3313.   if not TMRRobotic then
  3314.    begin
  3315.    rNutrientsAbsorbed.RoboticDMI[CowParity,WeekOfLactation-1]:=0;
  3316.    rNutrientsAbsorbed.LiquidDMI[CowParity,WeekOfLactation-1]:=0;
  3317.    end;
  3318.  
  3319. end;
  3320.  
  3321. function TMain.CopyDir(const fromDir, toDir: string): Boolean;
  3322. var
  3323.   fos: TSHFileOpStruct;
  3324. begin
  3325.   ZeroMemory(@fos, SizeOf(fos));
  3326.   with fos do
  3327.   begin
  3328.     wFunc  := FO_COPY;
  3329.     fFlags := FOF_FILESONLY;
  3330.     pFrom  := PChar(fromDir + #0);
  3331.     pTo    := PChar(toDir)
  3332.   end;
  3333.   Result := (0 = ShFileOperation(fos));
  3334. end;
  3335.  
  3336. procedure TMain.Currency1Click(Sender: TObject);
  3337. begin
  3338. if not Assigned(SelectCurrency) then
  3339.  Application.CreateForm(TSelectCurrency, SelectCurrency);
  3340. if SelectCurrency.ShowModal=mrOK then
  3341.  begin
  3342.  Welcome.Label1.Caption:=WCCurrency;
  3343.  Welcome.Label2.Caption:=WCAbbrev;
  3344.  end;
  3345. end;
  3346.  
  3347. function TMain.MoveDir(const fromDir, toDir: string): Boolean;
  3348. var
  3349.   fos: TSHFileOpStruct;
  3350. begin
  3351.   ZeroMemory(@fos, SizeOf(fos));
  3352.   with fos do
  3353.   begin
  3354.     wFunc  := FO_MOVE;
  3355.     fFlags := FOF_FILESONLY;
  3356.     pFrom  := PChar(fromDir + #0);
  3357.     pTo    := PChar(toDir)
  3358.   end;
  3359.   Result := (0 = ShFileOperation(fos));
  3360. end;
  3361.  
  3362. procedure TMain.SetUpDBFeedLabels;
  3363. begin
  3364. if not FileExists(DatabaseDirectory+'\DBFeedLabels.ph6') then
  3365.  CopyFile(PWideChar(DatabaseDirectory+'\Stored\DBFeedLabels.ph6'),PWideChar(DatabaseDirectory+'\DBFeedLabels.ph6'),False);
  3366. if (FileExists(DatabaseDirectory+'\DBFeedLabels.ph6')) or (not DBConnected) then
  3367.  begin
  3368.  EnDeCryptFile(DatabaseDirectory+'\DBFeedLabels.ph6');
  3369.  OpenFeedLabels;
  3370.  EnDeCryptFile(DatabaseDirectory+'\DBFeedLabels.ph6');
  3371.  if rTranslate.no225='' then
  3372.   begin
  3373.   DeleteFile(DatabaseDirectory+'\DBFeedLabels.ph6');
  3374.   CopyFile(PWideChar(DatabaseDirectory+'\Stored\DBFeedLabels.ph6'),PWideChar(DatabaseDirectory+'\DBFeedLabels.ph6'),False);
  3375.   EnDeCryptFile(DatabaseDirectory+'\DBFeedLabels.ph6');
  3376.   OpenFeedLabels;
  3377.   EnDeCryptFile(DatabaseDirectory+'\DBFeedLabels.ph6');
  3378.   end;
  3379.  end
  3380. else
  3381.  ReadLanguage;
  3382. end;
  3383.  
  3384. procedure TMain.SetUpDBFeedPrices;
  3385. begin
  3386. if (FileExists(DatabaseDirectory+'\DBFeedPrices.ph6')) or (not DBConnected)
  3387.  or (DBNotConnected=1) then
  3388.  begin
  3389.  EnDeCryptFile(DatabaseDirectory+'\DBFeedPrices.ph6');
  3390.  OpenFeedPrices;
  3391.  EnDeCryptFile(DatabaseDirectory+'\DBFeedPrices.ph6');
  3392.  if FeedPrice[1]>0 then
  3393.   begin
  3394.   DeleteFile(DatabaseDirectory+'\Daily\DBFeedPrices.ph6');
  3395.   CopyFile(PWideChar(DatabaseDirectory+'\DBFeedPrices.ph6'),PWideChar(DatabaseDirectory+'\Daily\DBFeedPrices.ph6'),False);
  3396.   end;
  3397.  end
  3398. else
  3399.  ReadFeedPrice;
  3400. end;
  3401.  
  3402.  
  3403.  
  3404. procedure TMain.ReadDBPreMix(n: Integer);
  3405. begin
  3406.   while not FDQuery1.Eof do
  3407.    begin
  3408.    DBPreMixes[n].New:=0;
  3409.    DBPreMixes[n].ID:=FDQuery1.FieldByName('ID').AsInteger;
  3410.    DBPreMixes[n].TypeF:=FDQuery1.FieldByName('Type').AsString;
  3411.    DBPreMixes[n].Name:=FDQuery1.FieldByName('NameEn').AsString;
  3412.    DBPreMixes[n].FC_1:=FDQuery1.FieldByName('FC1').AsString;
  3413.    DBPreMixes[n].FC_2:=FDQuery1.FieldByName('FC2').AsString;
  3414.    DBPreMixes[n].FC_3:=FDQuery1.FieldByName('FC3').AsString;
  3415.    DBPreMixes[n].FC_4:=FDQuery1.FieldByName('FC4').AsString;
  3416.    DBPreMixes[n].FC_5:=FDQuery1.FieldByName('FC5').AsString;
  3417.    DBPreMixes[n].FC_6:=FDQuery1.FieldByName('FC6').AsString;
  3418.    DBPreMixes[n].FC_7:=FDQuery1.FieldByName('FC7').AsString;
  3419.    DBPreMixes[n].FC_8:=FDQuery1.FieldByName('FC8').AsString;
  3420.    DBPreMixes[n].FC_9:=FDQuery1.FieldByName('FC9').AsString;
  3421.    DBPreMixes[n].FC_10:=FDQuery1.FieldByName('FC10').AsString;
  3422.    DBPreMixes[n].FC_11:=FDQuery1.FieldByName('FC11').AsString;
  3423.    DBPreMixes[n].FC_12:=FDQuery1.FieldByName('FC12').AsString;
  3424.    DBPreMixes[n].FC_13:=FDQuery1.FieldByName('FC13').AsString;
  3425.    DBPreMixes[n].FC_14:=FDQuery1.FieldByName('FC14').AsString;
  3426.    DBPreMixes[n].FC_15:=FDQuery1.FieldByName('FC15').AsString;
  3427.    DBPreMixes[n].FC_16:=FDQuery1.FieldByName('FC16').AsString;
  3428.    DBPreMixes[n].FC_17:=FDQuery1.FieldByName('FC17').AsString;
  3429.    DBPreMixes[n].FC_18:=FDQuery1.FieldByName('FC18').AsString;
  3430.    DBPreMixes[n].FN_1:=FDQuery1.FieldByName('FN1').AsString;
  3431.    DBPreMixes[n].FN_2:=FDQuery1.FieldByName('FN2').AsString;
  3432.    DBPreMixes[n].FN_3:=FDQuery1.FieldByName('FN3').AsString;
  3433.    DBPreMixes[n].FN_4:=FDQuery1.FieldByName('FN4').AsString;
  3434.    DBPreMixes[n].FN_5:=FDQuery1.FieldByName('FN5').AsString;
  3435.    DBPreMixes[n].FN_6:=FDQuery1.FieldByName('FN6').AsString;
  3436.    DBPreMixes[n].FN_7:=FDQuery1.FieldByName('FN7').AsString;
  3437.    DBPreMixes[n].FN_8:=FDQuery1.FieldByName('FN8').AsString;
  3438.    DBPreMixes[n].FN_9:=FDQuery1.FieldByName('FN9').AsString;
  3439.    DBPreMixes[n].FN_10:=FDQuery1.FieldByName('FN10').AsString;
  3440.    DBPreMixes[n].FN_11:=FDQuery1.FieldByName('FN11').AsString;
  3441.    DBPreMixes[n].FN_12:=FDQuery1.FieldByName('FN12').AsString;
  3442.    DBPreMixes[n].FN_13:=FDQuery1.FieldByName('FN13').AsString;
  3443.    DBPreMixes[n].FN_14:=FDQuery1.FieldByName('FN14').AsString;
  3444.    DBPreMixes[n].FN_15:=FDQuery1.FieldByName('FN15').AsString;
  3445.    DBPreMixes[n].FN_16:=FDQuery1.FieldByName('FN16').AsString;
  3446.    DBPreMixes[n].FN_17:=FDQuery1.FieldByName('FN17').AsString;
  3447.    DBPreMixes[n].FN_18:=FDQuery1.FieldByName('FN18').AsString;
  3448.    DBPreMixes[n].FA_1:=FDQuery1.FieldByName('FN1%').AsFloat;
  3449.    DBPreMixes[n].FA_2:=FDQuery1.FieldByName('FN2%').AsFloat;
  3450.    DBPreMixes[n].FA_3:=FDQuery1.FieldByName('FN3%').AsFloat;
  3451.    DBPreMixes[n].FA_4:=FDQuery1.FieldByName('FN4%').AsFloat;
  3452.    DBPreMixes[n].FA_5:=FDQuery1.FieldByName('FN5%').AsFloat;
  3453.    DBPreMixes[n].FA_6:=FDQuery1.FieldByName('FN6%').AsFloat;
  3454.    DBPreMixes[n].FA_7:=FDQuery1.FieldByName('FN7%').AsFloat;
  3455.    DBPreMixes[n].FA_8:=FDQuery1.FieldByName('FN8%').AsFloat;
  3456.    DBPreMixes[n].FA_9:=FDQuery1.FieldByName('FN9%').AsFloat;
  3457.    DBPreMixes[n].FA_10:=FDQuery1.FieldByName('FN10%').AsFloat;
  3458.    DBPreMixes[n].FA_11:=FDQuery1.FieldByName('FN11%').AsFloat;
  3459.    DBPreMixes[n].FA_12:=FDQuery1.FieldByName('FN12%').AsFloat;
  3460.    DBPreMixes[n].FA_13:=FDQuery1.FieldByName('FN13%').AsFloat;
  3461.    DBPreMixes[n].FA_14:=FDQuery1.FieldByName('FN14%').AsFloat;
  3462.    DBPreMixes[n].FA_15:=FDQuery1.FieldByName('FN15%').AsFloat;
  3463.    DBPreMixes[n].FA_16:=FDQuery1.FieldByName('FN16%').AsFloat;
  3464.    DBPreMixes[n].FA_17:=FDQuery1.FieldByName('FN17%').AsFloat;
  3465.    DBPreMixes[n].FA_18:=FDQuery1.FieldByName('FN18%').AsFloat;
  3466.    DBPreMixes[n].FP_1:=FDQuery1.FieldByName('FP_1').AsInteger;
  3467.    DBPreMixes[n].FP_2:=FDQuery1.FieldByName('FP_2').AsInteger;
  3468.    DBPreMixes[n].FP_3:=FDQuery1.FieldByName('FP_3').AsInteger;
  3469.    DBPreMixes[n].FP_4:=FDQuery1.FieldByName('FP_4').AsInteger;
  3470.    DBPreMixes[n].FP_5:=FDQuery1.FieldByName('FP_5').AsInteger;
  3471.    DBPreMixes[n].FP_6:=FDQuery1.FieldByName('FP_6').AsInteger;
  3472.    DBPreMixes[n].FP_7:=FDQuery1.FieldByName('FP_7').AsInteger;
  3473.    DBPreMixes[n].FP_8:=FDQuery1.FieldByName('FP_8').AsInteger;
  3474.    DBPreMixes[n].FP_9:=FDQuery1.FieldByName('FP_9').AsInteger;
  3475.    DBPreMixes[n].FP_10:=FDQuery1.FieldByName('FP_10').AsInteger;
  3476.    DBPreMixes[n].FP_11:=FDQuery1.FieldByName('FP_11').AsInteger;
  3477.    DBPreMixes[n].FP_12:=FDQuery1.FieldByName('FP_12').AsInteger;
  3478.    DBPreMixes[n].FP_13:=FDQuery1.FieldByName('FP_13').AsInteger;
  3479.    DBPreMixes[n].FP_14:=FDQuery1.FieldByName('FP_14').AsInteger;
  3480.    DBPreMixes[n].FP_15:=FDQuery1.FieldByName('FP_15').AsInteger;
  3481.    DBPreMixes[n].FP_16:=FDQuery1.FieldByName('FP_16').AsInteger;
  3482.    DBPreMixes[n].FP_17:=FDQuery1.FieldByName('FP_17').AsInteger;
  3483.    DBPreMixes[n].FP_18:=FDQuery1.FieldByName('FP_18').AsInteger;
  3484.    DBPreMixes[n].Cost:=FDQuery1.FieldByName('Price').AsFloat;
  3485.    DBPreMixes[n].BlendType:=FDQuery1.FieldByName('BlendType').AsString;
  3486.    inc(n);
  3487.    FDQuery1.Next;
  3488.    end;
  3489. end;
  3490.  
  3491. procedure TMain.SetUpDBPreMixes;
  3492. var
  3493. n: Integer;
  3494.  
  3495. begin
  3496. //DBNotConnected:=0;
  3497. if (DBConnected) and (DBNotConnected=0) then
  3498.  begin
  3499.  if (FileExists(DatabaseDirectory+'\DBPreMixes.ph6')) and (NewBlends=False)
  3500.   and (Administrator=False) and (UpdateYesNo=False) and (not DifferentHD) then
  3501.   begin
  3502.   n:=PreMixFeedsHigh;
  3503.   DBPreMixes:=nil;
  3504.   SetLength(DBPreMixes,n);
  3505.   EnDeCryptFile(DatabaseDirectory+'\DBPreMixes.ph6');
  3506.   OpenPreMix(n);
  3507.   EnDeCryptFile(DatabaseDirectory+'\DBPreMixes.ph6');
  3508. //  if n>PreMixFeedsHigh then
  3509. //   begin
  3510. //   SetLength(DBPreMixes,PreMixFeedsHigh+(n-PreMixFeedsHigh));
  3511. //   SetUpQueryPM(1);
  3512. //   ReadDBPreMix(PreMixFeedsHigh);
  3513. //   PreMixFeedsHigh:=Length(DBPreMixes);
  3514. //   FDQuery1.Close;
  3515. //   end;
  3516.   end
  3517.  else
  3518.   begin
  3519.   SetUpQueryPM(0);
  3520.   PreMixFeedsHigh:=FDQuery1.RecordCount;
  3521.   DBPreMixes:=nil;
  3522.   SetLength(DBPreMixes,PreMixFeedsHigh);
  3523.   n:=0;
  3524.   ReadDBPreMix(n);
  3525.   end;
  3526.  FDQuery1.Close;
  3527.  end
  3528. else
  3529.  begin
  3530.  DBPreMixes:=nil;
  3531.  if PreMixFeedsHigh>0 then
  3532.   begin
  3533.   SetLength(DBPreMixes,PreMixFeedsHigh);
  3534.   EnDeCryptFile(DatabaseDirectory+'\DBPreMixes.ph6');
  3535.   OpenPreMix(PreMixFeedsHigh);
  3536.   EnDeCryptFile(DatabaseDirectory+'\DBPreMixes.ph6');
  3537.   end;
  3538.  end;
  3539. end;
  3540.  
  3541. procedure TMain.ReadDBClient(n: Integer);
  3542. begin
  3543.   while not FDQuery1.Eof do
  3544.    begin
  3545.    DBClientFeeds[n].New:=0;
  3546.    DBClientFeeds[n].ID:=FDQuery1.FieldByName('ID').AsInteger;
  3547.    DBClientFeeds[n].Cost:=FDQuery1.FieldByName('Cost').AsInteger;
  3548.    DBClientFeeds[n].TypeF:=FDQuery1.FieldByName('Type').AsString;
  3549.    DBClientFeeds[n].Forage:=FDQuery1.FieldByName('Forage').AsString;
  3550.    DBClientFeeds[n].ForageFr:=FDQuery1.FieldByName('ForageFr').AsString;
  3551.    DBClientFeeds[n].ForageUS:=FDQuery1.FieldByName('ForageUS').AsString;
  3552.    DBClientFeeds[n].ForageSp:=FDQuery1.FieldByName('ForageSp').AsString;
  3553.    DBClientFeeds[n].Code:=FDQuery1.FieldByName('Code').AsString;
  3554.    if FDQuery1.FieldByName('Sup').AsInteger=1 then
  3555.     DBClientFeeds[n].Sup:=False
  3556.    else
  3557.     DBClientFeeds[n].Sup:=True;
  3558.    if FDQuery1.FieldByName('LongP').AsInteger=1 then
  3559.     DBClientFeeds[n].Long:=True
  3560.    else
  3561.     DBClientFeeds[n].Long:=False;
  3562.    DBClientFeeds[n].LongForage:=False;
  3563.    DBClientFeeds[n].TCHO:=FDQuery1.FieldByName('TCHO').AsFloat;
  3564.    DBClientFeeds[n].NDF:=FDQuery1.FieldByName('NDF').AsFloat;
  3565.    DBClientFeeds[n].PemNDF:=FDQuery1.FieldByName('PemNDF').AsFloat;
  3566.    DBClientFeeds[n].CP:=FDQuery1.FieldByName('CP').AsFloat;
  3567.    DBClientFeeds[n].RateBcho:=FDQuery1.FieldByName('RateBcho').AsFloat;
  3568.    DBClientFeeds[n].Bcho:=FDQuery1.FieldByName('Bcho').AsFloat;
  3569.    DBClientFeeds[n].Acho:=FDQuery1.FieldByName('Acho').AsFloat;
  3570.    DBClientFeeds[n].SNDF:=FDQuery1.FieldByName('SNDF').AsFloat;
  3571.    DBClientFeeds[n].Starch:=FDQuery1.FieldByName('Starch').AsFloat;
  3572.    DBClientFeeds[n].RateAcho:=FDQuery1.FieldByName('RateAcho').AsFloat;
  3573.    DBClientFeeds[n].RateBCP:=FDQuery1.FieldByName('RateBCP').AsFloat;
  3574.    DBClientFeeds[n].BCP:=FDQuery1.FieldByName('BCP').AsFloat;
  3575.    DBClientFeeds[n].ACP:=FDQuery1.FieldByName('ACP').AsFloat;
  3576.    DBClientFeeds[n].RateACP:=FDQuery1.FieldByName('RateACP').AsFloat;
  3577.    DBClientFeeds[n].Nlag:=FDQuery1.FieldByName('Nlag').AsFloat;
  3578.    DBClientFeeds[n].Ash:=FDQuery1.FieldByName('Ash').AsFloat;
  3579.    DBClientFeeds[n].Fat:=FDQuery1.FieldByName('Fat').AsFloat;
  3580.    DBClientFeeds[n].VFA:=FDQuery1.FieldByName('VFA').AsFloat;
  3581.    DBClientFeeds[n].Lactic:=FDQuery1.FieldByName('Lactic').AsFloat;
  3582.    DBClientFeeds[n].NH3:=FDQuery1.FieldByName('NH3').AsFloat;
  3583.    DBClientFeeds[n].DM:=FDQuery1.FieldByName('DM').AsFloat;
  3584.    DBClientFeeds[n].GasA:=FDQuery1.FieldByName('GasA').AsFloat;
  3585.    DBClientFeeds[n].GasB:=FDQuery1.FieldByName('GasB').AsFloat;
  3586.    DBClientFeeds[n].GasARate:=FDQuery1.FieldByName('GasARate').AsFloat;
  3587.    DBClientFeeds[n].GasBRate:=FDQuery1.FieldByName('GasBRate').AsFloat;
  3588.    DBClientFeeds[n].GasBLag:=FDQuery1.FieldByName('GasBLag').AsFloat;
  3589.    DBClientFeeds[n].Starchfim:=FDQuery1.FieldByName('Starchfim').AsFloat;
  3590.    DBClientFeeds[n].Fip:=FDQuery1.FieldByName('Fip').AsFloat;
  3591.    DBClientFeeds[n].ME:=FDQuery1.FieldByName('ME').AsFloat;
  3592.    DBClientFeeds[n].An:=FDQuery1.FieldByName('An').AsFloat;
  3593.    DBClientFeeds[n].Sn:=FDQuery1.FieldByName('Sn').AsFloat;
  3594.    DBClientFeeds[n].Bn:=FDQuery1.FieldByName('Bn').AsFloat;
  3595.    DBClientFeeds[n].Cn:=FDQuery1.FieldByName('Cn').AsFloat;
  3596.    DBClientFeeds[n].Adin:=FDQuery1.FieldByName('Adin').AsFloat;
  3597.    DBClientFeeds[n].Lys:=FDQuery1.FieldByName('Lys').AsFloat;
  3598.    DBClientFeeds[n].Thr:=FDQuery1.FieldByName('Thr').AsFloat;
  3599.    DBClientFeeds[n].Met:=FDQuery1.FieldByName('Met').AsFloat;
  3600.    DBClientFeeds[n].Cys:=FDQuery1.FieldByName('Cys').AsFloat;
  3601.    DBClientFeeds[n].His:=FDQuery1.FieldByName('His').AsFloat;
  3602.    DBClientFeeds[n].Sdm:=FDQuery1.FieldByName('Sdm').AsFloat;
  3603.    DBClientFeeds[n].Tfa:=FDQuery1.FieldByName('Tfa').AsFloat;
  3604.    DBClientFeeds[n].Adm:=FDQuery1.FieldByName('Adm').AsFloat;
  3605.    DBClientFeeds[n].Bdm:=FDQuery1.FieldByName('Bdm').AsFloat;
  3606.    DBClientFeeds[n].Cdm:=FDQuery1.FieldByName('Cdm').AsFloat;
  3607.    DBClientFeeds[n].Domd:=FDQuery1.FieldByName('Domd').AsFloat;
  3608.    DBClientFeeds[n].Ph:=FDQuery1.FieldByName('Ph').AsFloat;
  3609.    DBClientFeeds[n].Ca:=FDQuery1.FieldByName('Ca').AsFloat;
  3610.    DBClientFeeds[n].P:=FDQuery1.FieldByName('P').AsFloat;
  3611.    DBClientFeeds[n].Mg:=FDQuery1.FieldByName('Mg').AsFloat;
  3612.    DBClientFeeds[n].K:=FDQuery1.FieldByName('K').AsFloat;
  3613.    DBClientFeeds[n].Na:=FDQuery1.FieldByName('Na').AsFloat;
  3614.    DBClientFeeds[n].Cl:=FDQuery1.FieldByName('Cl').AsFloat;
  3615.    DBClientFeeds[n].S:=FDQuery1.FieldByName('S').AsFloat;
  3616.    DBClientFeeds[n].Cu:=FDQuery1.FieldByName('Cu').AsFloat;
  3617.    DBClientFeeds[n].Zn:=FDQuery1.FieldByName('Zn').AsFloat;
  3618.    DBClientFeeds[n].Mn:=FDQuery1.FieldByName('Mn').AsFloat;
  3619.    DBClientFeeds[n].Co:=FDQuery1.FieldByName('Co').AsFloat;
  3620.    DBClientFeeds[n].I:=FDQuery1.FieldByName('I').AsFloat;
  3621.    DBClientFeeds[n].Se:=FDQuery1.FieldByName('Se').AsFloat;
  3622.    DBClientFeeds[n].Fe:=FDQuery1.FieldByName('Fe').AsFloat;
  3623.    DBClientFeeds[n].Mo:=FDQuery1.FieldByName('Mo').AsFloat;
  3624.    inc(n);
  3625.    FDQuery1.Next;
  3626.    end;
  3627. end;
  3628.  
  3629. procedure TMain.SetUpDBClientFeeds;
  3630. var
  3631. n,LCClientFeedsHigh,m: Integer;
  3632.  
  3633. begin
  3634. //DBNotConnected:=0;
  3635. if (DBConnected) and (DBNotConnected=0) then
  3636.  begin
  3637. //DBClientFeeds has to be there or it is created. If UpdateYesNo is selected, DBClientFeeds is created
  3638. //if in the Database, more is there relative to ClientFeedsHigh (one or more added by someone), then n will be higher
  3639. //than ClientFeedsHigh and extra are put in
  3640.  if (FileExists(DatabaseDirectory+'\DBClientFeeds.ph6')) and
  3641.      {(NewClients=False) and} (Administrator=False) and (UpdateYesNo=False)
  3642.      and (not DifferentHD) then   //{((n>=ClientFeedsHigh) or }
  3643.   begin
  3644.   n:=ClientFeedsHigh;
  3645.   m:=n;
  3646.   DBClientFeeds:=nil;
  3647.   SetLength(DBClientFeeds,n);
  3648.   EnDeCryptFile(DatabaseDirectory+'\DBClientFeeds.ph6');
  3649.   OpenClient(ClientFeedsHigh);
  3650.   EnDeCryptFile(DatabaseDirectory+'\DBClientFeeds.ph6');
  3651.   if (n>m) then
  3652.    begin
  3653. //   SetLength(DBClientFeeds,ClientFeedsHigh+(n-ClientFeedsHigh));
  3654.    SetUpQuery(1);
  3655.    ReadDBClient(m);
  3656.    ClientFeedsHigh:=Length(DBClientFeeds);
  3657.    FDQuery1.Close;
  3658.    end;
  3659.   end
  3660.  else
  3661.   begin
  3662.   SetUpQuery(0);
  3663.   ClientFeedsHigh:=FDQuery1.RecordCount;
  3664.   DBClientFeeds:=nil;
  3665.   SetLength(DBClientFeeds,ClientFeedsHigh);
  3666.   n:=0;
  3667. //put try except in here to catch possible bug in reading FDQuery1
  3668.   ReadDBClient(n);
  3669.   end;
  3670.  FDQuery1.Close;
  3671.  end
  3672. else
  3673.  begin
  3674.  DBClientFeeds:=nil;
  3675.  if ClientFeedsHigh>0 then
  3676.   begin
  3677.   SetLength(DBClientFeeds,ClientFeedsHigh);
  3678.   EnDeCryptFile(DatabaseDirectory+'\DBClientFeeds.ph6');
  3679.   LCClientFeedsHigh:=linecount(DatabaseDirectory+'\DBClientFeeds.ph6');
  3680.   if ClientFeedsHigh<LCClientFeedsHigh then
  3681.    begin
  3682.    DBClientFeeds:=nil;
  3683.    SetLength(DBClientFeeds,LCClientFeedsHigh);
  3684.    OpenClient(LCClientFeedsHigh);
  3685.    end
  3686.   else
  3687.    begin
  3688.    OpenClient(ClientFeedsHigh);
  3689.    end;
  3690.   EnDeCryptFile(DatabaseDirectory+'\DBClientFeeds.ph6');
  3691.   end;
  3692.  end;
  3693. end;
  3694.  
  3695.  
  3696. procedure TMain.SetUpDBMasterFeeds;
  3697. var
  3698. n,m: Integer;
  3699.  
  3700. begin
  3701. if DBConnected then
  3702.  begin
  3703.  if (FileExists(DatabaseDirectory+'\DBMasterFeeds.ph6')) {and (n=MasterFeedsHigh) }
  3704.    and (NewMaster=False) and (Administrator=False) and (UpdateYesNo=False)
  3705.    and (not DifferentHD) then
  3706.   begin
  3707.   n:=MasterFeedsHigh;
  3708.   DBMasterFeeds:=nil;
  3709.   SetLength(DBMasterFeeds,n);
  3710.   EnDeCryptFile(DatabaseDirectory+'\DBMasterFeeds.ph6');
  3711.   OpenMaster(n);
  3712.   EnDeCryptFile(DatabaseDirectory+'\DBMasterFeeds.ph6');
  3713.   end
  3714.  else
  3715.   begin
  3716.   with FDQuery1 do
  3717.    begin
  3718.    DisableControls;
  3719.    Close;
  3720.    SQL.Clear;
  3721.    SQL.Add('SELECT *');
  3722.    SQL.Add('FROM Master');
  3723.    SQL.Add('WHERE "Show"=0');
  3724.    Open;
  3725.    EnableControls;
  3726.    end;
  3727.   m:=FDQuery1.RecordCount;
  3728.   MasterFeedsHigh:=m;
  3729.   DBMasterFeeds:=nil;
  3730.   SetLength(DBMasterFeeds,m);
  3731.   n:=0;
  3732.   FDQuery1.First;
  3733.   while not FDQuery1.Eof do
  3734.    begin
  3735.    DBMasterFeeds[n].New:=0;
  3736.    DBMasterFeeds[n].ID:=FDQuery1.FieldByName('ID').AsInteger;
  3737.    DBMasterFeeds[n].Cost:=FDQuery1.FieldByName('Cost').AsInteger;
  3738.    DBMasterFeeds[n].TypeF:=FDQuery1.FieldByName('Type').AsString;
  3739.    DBMasterFeeds[n].Forage:=FDQuery1.FieldByName('Forage').AsString;
  3740.    DBMasterFeeds[n].ForageFr:=FDQuery1.FieldByName('ForageFr').AsString;
  3741.    DBMasterFeeds[n].ForageUS:=FDQuery1.FieldByName('ForageUS').AsString;
  3742.    DBMasterFeeds[n].ForageSp:=FDQuery1.FieldByName('ForageSp').AsString;
  3743.    DBMasterFeeds[n].Code:=FDQuery1.FieldByName('Code').AsString;
  3744.    if FDQuery1.FieldByName('Sup').AsString='1' then
  3745.     DBMasterFeeds[n].Sup:=False
  3746.    else
  3747.     DBMasterFeeds[n].Sup:=True;
  3748.    if FDQuery1.FieldByName('LongP').AsString='1' then
  3749.     DBMasterFeeds[n].Long:=True
  3750.    else
  3751.     DBMasterFeeds[n].Long:=False;
  3752.    DBMasterFeeds[n].LongForage:=False;
  3753.    DBMasterFeeds[n].TCHO:=FDQuery1.FieldByName('TCHO').AsFloat;
  3754.    DBMasterFeeds[n].NDF:=FDQuery1.FieldByName('NDF').AsFloat;
  3755.    DBMasterFeeds[n].PemNDF:=FDQuery1.FieldByName('PemNDF').AsFloat;
  3756.    DBMasterFeeds[n].CP:=FDQuery1.FieldByName('CP').AsFloat;
  3757.    DBMasterFeeds[n].RateBcho:=FDQuery1.FieldByName('RateBcho').AsFloat;
  3758.    DBMasterFeeds[n].Bcho:=FDQuery1.FieldByName('Bcho').AsFloat;
  3759.    DBMasterFeeds[n].Acho:=FDQuery1.FieldByName('Acho').AsFloat;
  3760.    DBMasterFeeds[n].SNDF:=FDQuery1.FieldByName('SNDF').AsFloat;
  3761.    DBMasterFeeds[n].Starch:=FDQuery1.FieldByName('Starch').AsFloat;
  3762.    DBMasterFeeds[n].RateAcho:=FDQuery1.FieldByName('RateAcho').AsFloat;
  3763.    DBMasterFeeds[n].RateBCP:=FDQuery1.FieldByName('RateBCP').AsFloat;
  3764.    DBMasterFeeds[n].BCP:=FDQuery1.FieldByName('BCP').AsFloat;
  3765.    DBMasterFeeds[n].ACP:=FDQuery1.FieldByName('ACP').AsFloat;
  3766.    DBMasterFeeds[n].RateACP:=FDQuery1.FieldByName('RateACP').AsFloat;
  3767.    DBMasterFeeds[n].Nlag:=FDQuery1.FieldByName('Nlag').AsFloat;
  3768.    DBMasterFeeds[n].Ash:=FDQuery1.FieldByName('Ash').AsFloat;
  3769.    DBMasterFeeds[n].Fat:=FDQuery1.FieldByName('Fat').AsFloat;
  3770.    DBMasterFeeds[n].VFA:=FDQuery1.FieldByName('VFA').AsFloat;
  3771.    DBMasterFeeds[n].Lactic:=FDQuery1.FieldByName('Lactic').AsFloat;
  3772.    DBMasterFeeds[n].NH3:=FDQuery1.FieldByName('NH3').AsFloat;
  3773.    DBMasterFeeds[n].DM:=FDQuery1.FieldByName('DM').AsFloat;
  3774.    DBMasterFeeds[n].GasA:=FDQuery1.FieldByName('GasA').AsFloat;
  3775.    DBMasterFeeds[n].GasB:=FDQuery1.FieldByName('GasB').AsFloat;
  3776.    DBMasterFeeds[n].GasARate:=FDQuery1.FieldByName('GasARate').AsFloat;
  3777.    DBMasterFeeds[n].GasBRate:=FDQuery1.FieldByName('GasBRate').AsFloat;
  3778.    DBMasterFeeds[n].GasBLag:=FDQuery1.FieldByName('GasBLag').AsFloat;
  3779.    DBMasterFeeds[n].Starchfim:=FDQuery1.FieldByName('Starchfim').AsFloat;
  3780.    DBMasterFeeds[n].Fip:=FDQuery1.FieldByName('Fip').AsFloat;
  3781.    DBMasterFeeds[n].ME:=FDQuery1.FieldByName('ME').AsFloat;
  3782.    DBMasterFeeds[n].An:=FDQuery1.FieldByName('An').AsFloat;
  3783.    DBMasterFeeds[n].Sn:=FDQuery1.FieldByName('Sn').AsFloat;
  3784.    DBMasterFeeds[n].Bn:=FDQuery1.FieldByName('Bn').AsFloat;
  3785.    DBMasterFeeds[n].Cn:=FDQuery1.FieldByName('Cn').AsFloat;
  3786.    DBMasterFeeds[n].Adin:=FDQuery1.FieldByName('Adin').AsFloat;
  3787.    DBMasterFeeds[n].Lys:=FDQuery1.FieldByName('Lys').AsFloat;
  3788.    DBMasterFeeds[n].Thr:=FDQuery1.FieldByName('Thr').AsFloat;
  3789.    DBMasterFeeds[n].Met:=FDQuery1.FieldByName('Met').AsFloat;
  3790.    DBMasterFeeds[n].Cys:=FDQuery1.FieldByName('Cys').AsFloat;
  3791.    DBMasterFeeds[n].His:=FDQuery1.FieldByName('His').AsFloat;
  3792.    DBMasterFeeds[n].Sdm:=FDQuery1.FieldByName('Sdm').AsFloat;
  3793.    DBMasterFeeds[n].Tfa:=FDQuery1.FieldByName('Tfa').AsFloat;
  3794.    DBMasterFeeds[n].Adm:=FDQuery1.FieldByName('Adm').AsFloat;
  3795.    DBMasterFeeds[n].Bdm:=FDQuery1.FieldByName('Bdm').AsFloat;
  3796.    DBMasterFeeds[n].Cdm:=FDQuery1.FieldByName('Cdm').AsFloat;
  3797.    DBMasterFeeds[n].Domd:=FDQuery1.FieldByName('Domd').AsFloat;
  3798.    DBMasterFeeds[n].Ph:=FDQuery1.FieldByName('Ph').AsFloat;
  3799.    DBMasterFeeds[n].Ca:=FDQuery1.FieldByName('Ca').AsFloat;
  3800.    DBMasterFeeds[n].P:=FDQuery1.FieldByName('P').AsFloat;
  3801.    DBMasterFeeds[n].Mg:=FDQuery1.FieldByName('Mg').AsFloat;
  3802.    DBMasterFeeds[n].K:=FDQuery1.FieldByName('K').AsFloat;
  3803.    DBMasterFeeds[n].Na:=FDQuery1.FieldByName('Na').AsFloat;
  3804.    DBMasterFeeds[n].Cl:=FDQuery1.FieldByName('Cl').AsFloat;
  3805.    DBMasterFeeds[n].S:=FDQuery1.FieldByName('S').AsFloat;
  3806.    DBMasterFeeds[n].Cu:=FDQuery1.FieldByName('Cu').AsFloat;
  3807.    DBMasterFeeds[n].Zn:=FDQuery1.FieldByName('Zn').AsFloat;
  3808.    DBMasterFeeds[n].Mn:=FDQuery1.FieldByName('Mn').AsFloat;
  3809.    DBMasterFeeds[n].Co:=FDQuery1.FieldByName('Co').AsFloat;
  3810.    DBMasterFeeds[n].I:=FDQuery1.FieldByName('I').AsFloat;
  3811.    DBMasterFeeds[n].Se:=FDQuery1.FieldByName('Se').AsFloat;
  3812.    DBMasterFeeds[n].Fe:=FDQuery1.FieldByName('Fe').AsFloat;
  3813.    DBMasterFeeds[n].Mo:=FDQuery1.FieldByName('Mo').AsFloat;
  3814.    inc(n);
  3815.    FDQuery1.Next;
  3816.    end;
  3817.   end;
  3818.  FDQuery1.Close;
  3819.  end
  3820. else
  3821.  begin
  3822.  DBMasterFeeds:=nil;
  3823.  SetLength(DBMasterFeeds,MasterFeedsHigh);
  3824.   EnDeCryptFile(DatabaseDirectory+'\DBMasterFeeds.ph6');
  3825.   OpenMaster(MasterFeedsHigh);
  3826.   EnDeCryptFile(DatabaseDirectory+'\DBMasterFeeds.ph6');
  3827.  end;
  3828. end;
  3829.  
  3830. procedure TMain.GetMinerals;
  3831. var
  3832. n,m: Integer;
  3833. FeedName: array of TFeedName;
  3834.  
  3835. begin
  3836. if (DBConnected) and (not (FileExists(DatabaseDirectory+'\DBMinerals.ph6'))
  3837.  or (NewMineral)) then
  3838.  begin
  3839.   with FDQuery1 do
  3840.    begin
  3841.    DisableControls;
  3842.    Close;
  3843.    SQL.Clear;
  3844.    SQL.Add('SELECT *');
  3845.    SQL.Add('FROM Minerals ');
  3846.    SQL.Add('WHERE  ConsultantID =:apptype OR  ConsultantID =-1');
  3847.    FDQuery1.Params[0].Value:=Consultant;
  3848.    Open;
  3849.    EnableControls;
  3850.    end;
  3851.   Mineral:=nil;
  3852.   SetLength(Mineral,FDQuery1.RecordCount);
  3853.   FDQuery1.First;
  3854.   n:=0;
  3855.   while not FDQuery1.Eof do
  3856.    begin
  3857.    Mineral[n].TypeOfMineral:=FDQuery1.FieldByName('Type').AsInteger;
  3858.    Mineral[n].MineralID:=FDQuery1.FieldByName('MineralID').AsInteger;
  3859.    Mineral[n].ForageID:=FDQuery1.FieldByName('ForageID').AsInteger;
  3860.    Mineral[n].FarmerID:=FDQuery1.FieldByName('FarmerID').AsInteger;
  3861.    Mineral[n].Ca:=FDQuery1.FieldByName('Ca').AsSingle;
  3862.    Mineral[n].P:=FDQuery1.FieldByName('P').AsSingle;
  3863.    Mineral[n].Mg:=FDQuery1.FieldByName('Mg').AsSingle;
  3864.    Mineral[n].K:=FDQuery1.FieldByName('K').AsSingle;
  3865.    Mineral[n].Na:=FDQuery1.FieldByName('Na').AsSingle;
  3866.    Mineral[n].Cl:=FDQuery1.FieldByName('Cl').AsSingle;
  3867.    Mineral[n].S:=FDQuery1.FieldByName('S').AsSingle;
  3868.    Mineral[n].Cu:=FDQuery1.FieldByName('Cu').AsSingle;
  3869.    Mineral[n].Zn:=FDQuery1.FieldByName('Zn').AsSingle;
  3870.    Mineral[n].Mn:=FDQuery1.FieldByName('Mn').AsSingle;
  3871.    Mineral[n].Co:=FDQuery1.FieldByName('Co').AsSingle;
  3872.    Mineral[n].I:=FDQuery1.FieldByName('I').AsSingle;
  3873.    Mineral[n].Se:=FDQuery1.FieldByName('Se').AsSingle;
  3874.    Mineral[n].Fe:=FDQuery1.FieldByName('Fe').AsSingle;
  3875.    Mineral[n].Mo:=FDQuery1.FieldByName('Mo').AsSingle;
  3876.    inc(n);
  3877.    FDQuery1.Next;
  3878.    end;
  3879.   with FDQuery1 do
  3880.    begin
  3881.    DisableControls;
  3882.    Close;
  3883.    SQL.Clear;
  3884.    SQL.Add('SELECT  ID , Forage ');
  3885.    SQL.Add('FROM  Client ');
  3886.    SQL.Add('WHERE  Consultant =:apptype');
  3887.    FDQuery1.Params[0].Value:=Consultant;
  3888.    Open;
  3889.    EnableControls;
  3890.    end;
  3891.   FeedName:=nil;
  3892.   SetLength(FeedName,FDQuery1.RecordCount);
  3893.   n:=0;
  3894.   FDQuery1.First;
  3895.   while not FDQuery1.Eof do
  3896.    begin
  3897.    FeedName[n].ForageID:=FDQuery1.FieldByName('ID').AsInteger;
  3898.    FeedName[n].FeedNameString:=FDQuery1.FieldByName('Forage').AsString;
  3899.    inc(n);
  3900.    FDQuery1.Next;
  3901.    end;
  3902.  FDQuery1.Close;
  3903.  
  3904.  FDConnection1.Connected:=False;
  3905.  for n := 0 to Length(FeedName)-1 do
  3906.    begin
  3907.    for m := 0 to Length(Mineral)-1 do
  3908.     begin
  3909.     if Mineral[m].ForageID=FeedName[n].ForageID then
  3910.      Mineral[m].ForageName:=FeedName[n].FeedNameString;
  3911.     end;
  3912.    end;
  3913.  SaveMinerals;
  3914.  EnDeCryptFile(DatabaseDirectory+'\DBMinerals.ph6');
  3915.  end
  3916. else
  3917.  begin
  3918.  end;
  3919. end;
  3920.  
  3921. procedure TMain.DateToRestrictCDB;
  3922. var
  3923. RDB: String;
  3924. IndexPosn: Integer;
  3925. YearRDB,MonthRDB,DayRDB: Word;
  3926.  
  3927. begin
  3928. RDB:=DateChosenToRestrictDB;
  3929. IndexPosn:=LastDelimiter('-',RDB);
  3930. YearRDB:=StrToInt(Copy(RDB,IndexPosn+1,Length(RDB)-IndexPosn));
  3931. Delete(RDB,IndexPosn,Length(RDB)-IndexPosn+1);
  3932. IndexPosn:=LastDelimiter('-',RDB);
  3933. MonthRDB:=StrToInt(Copy(RDB,IndexPosn+1,Length(RDB)-IndexPosn));
  3934. Delete(RDB,IndexPosn,Length(RDB)-IndexPosn+1);
  3935. DayRDB:=StrToInt(RDB);
  3936. RestrictedDate:=EncodeDate(YearRDB,MonthRDB,DayRDB);
  3937. DateInteger:=Trunc(RestrictedDate);
  3938.  
  3939. RDB:=DateChosenToRestrictDBPM;
  3940. IndexPosn:=LastDelimiter('-',RDB);
  3941. YearRDB:=StrToInt(Copy(RDB,IndexPosn+1,Length(RDB)-IndexPosn));
  3942. Delete(RDB,IndexPosn,Length(RDB)-IndexPosn+1);
  3943. IndexPosn:=LastDelimiter('-',RDB);
  3944. MonthRDB:=StrToInt(Copy(RDB,IndexPosn+1,Length(RDB)-IndexPosn));
  3945. Delete(RDB,IndexPosn,Length(RDB)-IndexPosn+1);
  3946. DayRDB:=StrToInt(RDB);
  3947. RestrictedDatePM:=EncodeDate(YearRDB,MonthRDB,DayRDB);
  3948. DateIntegerPM:=Trunc(RestrictedDatePM);
  3949.  
  3950. //RestrictedDateFarmer:=EncodeDate(YearRDB,MonthRDB,DayRDB);
  3951. //DateIntegerFarmer:=YearChosenToRestrictDBFarmer;
  3952. end;
  3953.  
  3954.  
  3955.  
  3956. procedure TMain.SpeedButton1Click(Sender: TObject);
  3957. begin
  3958. Instant.Show;
  3959. if (MUL) and (ForageCalc) then ForageEnough.Show;
  3960. end;
  3961.  
  3962.  
  3963. procedure TMain.SpeedButton8Click(Sender: TObject);
  3964. var
  3965. Checks,m,n,t,TimePoint: Integer;
  3966.  
  3967. begin
  3968. if ChoosePrint.ShowModal=mrOK then
  3969.  begin
  3970.  Screen.Cursor:=crHourGlass;
  3971.  try
  3972.   begin
  3973.   m:=0;t:=0;
  3974.   for n:=1 to 12 do
  3975.    begin
  3976.    if FeedLength[n].Start<FeedLength[n].Finish then inc(m);
  3977.    end;
  3978.   Checks:=0;
  3979.   if ChoosePrint.CheckBox5.Checked then Checks:=Checks+1;
  3980.   if ChoosePrint.CheckBox7.Checked then Checks:=Checks+1;
  3981.   if ChoosePrint.CheckBox12.Checked then Checks:=Checks+m;
  3982.   if (ChoosePrint.CheckBox12.Checked) and (PreMixParlourNo>1) then Checks:=Checks+1;
  3983.   if (ChoosePrint.CheckBox12.Checked) and (PreMixRoboticNo>1) then Checks:=Checks+1;
  3984.  
  3985.   Printer.BeginDoc;
  3986.   try
  3987.    begin
  3988.    Printer.Title:=rTranslate.no13;
  3989.    if ChoosePrint.CheckBox5.Checked then
  3990.     begin
  3991.  if Beef then TimePoint:=1
  3992.  else
  3993.   begin
  3994.   if LeftStr(Instant.Edit66.Text,1)='-' then
  3995.    TimePoint:=Round(LactationLength/DaysInWeek)+7
  3996.                  +StrToInt(Instant.Edit66.Text)
  3997.   else
  3998.    TimePoint:=StrToInt(Instant.Edit66.Text);
  3999.   end;
  4000.     SingleRunOutPut(Printer.Canvas,@Feeding,Printer.PageWidth,Printer.PageHeight,
  4001.                     TimePoint,1);
  4002.     if Checks-1>1 then Printer.NewPage;
  4003.     end;
  4004.    if ChoosePrint.CheckBox7.Checked then
  4005.     begin
  4006.     Diets1(Printer.Canvas,@Feeding,Printer.PageWidth,Printer.PageHeight,1);
  4007.     if Checks-1>1 then Printer.NewPage;
  4008.     end;
  4009.    if ChoosePrint.CheckBox12.Checked then
  4010.     begin
  4011.     for n:=1 to m do
  4012.      begin
  4013.      PrintPreMix(Printer.Canvas,Printer.PageWidth,Printer.PageHeight,n,t,1);
  4014.      if Checks-1>1 then Printer.NewPage;
  4015.      end;
  4016.     if PreMixParlourNo>1 then
  4017.      begin
  4018.      PreMixParlour(Printer.Canvas,Printer.PageWidth,Printer.PageHeight,ChoosePrint.Edit1.Text);
  4019.      if Checks-1>1 then Printer.NewPage;
  4020.      end;
  4021.     if PreMixRoboticNo>1 then
  4022.      begin
  4023.      PreMixRobotic(Printer.Canvas,Printer.PageWidth,Printer.PageHeight,ChoosePrint.Edit1.Text);
  4024.      if Checks-1>1 then Printer.NewPage;
  4025.      end;
  4026.     end;
  4027.    Printer.EndDoc;
  4028.    end
  4029.   except
  4030.    on Exception do
  4031.     begin
  4032.     Printer.Abort;
  4033.     Printer.EndDoc;
  4034.     Raise;
  4035.     end;
  4036.   end;
  4037.   end
  4038.  finally
  4039.   Screen.Cursor:=crDefault;
  4040.  end;
  4041.  end;
  4042. end;
  4043.  
  4044. procedure TMain.TrackBar1EndDrag(Sender, Target: TObject; X, Y: Integer);
  4045. begin
  4046. SpeedButton6.Click;
  4047.  
  4048. end;
  4049.  
  4050. procedure TMain.SpeedButton7Click(Sender: TObject);
  4051. begin
  4052. if Farmer.FD<>'' then
  4053.  begin
  4054.  if (Farmer.Code<>'') then
  4055.   begin
  4056.   SaveAll;
  4057.   end;
  4058.  end;
  4059. end;
  4060.  
  4061. procedure TMain.SpeedButton10Click(Sender: TObject);
  4062. var
  4063. FilePath,CurrentDate,D1,D2,CurrentTime,T1: String;
  4064. m,n,t,TimePoint,IndexPosn: Integer;
  4065.  
  4066. begin
  4067. CurrentDate:=DateToStr(Date);
  4068. IndexPosn:=LastDelimiter('/',CurrentDate);
  4069. D1:=Copy(CurrentDate,IndexPosn+1,Length(CurrentDate)-IndexPosn);
  4070. Delete(CurrentDate,IndexPosn,Length(CurrentDate)-IndexPosn+1);
  4071. IndexPosn:=LastDelimiter('/',CurrentDate);
  4072. D2:=Copy(CurrentDate,IndexPosn+1,Length(CurrentDate)-IndexPosn);
  4073. Delete(CurrentDate,IndexPosn,Length(CurrentDate)-IndexPosn+1);
  4074. CurrentTime:=TimeToStr(Time);
  4075. IndexPosn:=LastDelimiter(':',CurrentTime);
  4076. Delete(CurrentTime,IndexPosn,Length(CurrentTime)-IndexPosn+1);
  4077. IndexPosn:=LastDelimiter(':',CurrentTime);
  4078. T1:=Copy(CurrentTime,IndexPosn+1,Length(CurrentTime)-IndexPosn);
  4079. Delete(CurrentTime,IndexPosn,Length(CurrentTime)-IndexPosn+1);
  4080. PDFFileName:='';
  4081. TodayDate:=CurrentDate+'-'+D2+'-'+D1;
  4082. if (PDF.ShowModal=mrOK) or (RunPDF) then
  4083.  begin
  4084.  PdfBox1.PaperSizeName:='A4';
  4085.  if BatchMode then
  4086.   begin
  4087.   FilePath:=BatchModePath+'\Completed\'+Farmer.Code+'\'+Farmer.FD;
  4088.   end
  4089.  else
  4090.   begin
  4091.   FilePath:=ClientDirectory+'\'+Farmer.Code+'\'+Farmer.FD;
  4092.   end;
  4093.  if not DirectoryExists(FilePath) then ForceDirectories(FilePath);
  4094.  PDFFileName:=CurrentDate+'-'+D2+'-'+D1+' '
  4095.                    +CurrentTime+'h'+T1+'m'+' '+Farmer.FD;
  4096.  if SetNameP.ShowModal=mrOK then
  4097.   PDFFileName:=SetNameP.Edit1.Text;
  4098.  if PDF.CheckBox5.Checked then
  4099.   begin
  4100.   PdfBox1.FileName:=FilePath+'\'+PDFFileName+' SR.pdf';
  4101.   PdfBox1.BeginDoc;
  4102.   if Beef then TimePoint:=1
  4103.   else
  4104.    begin
  4105.    if LeftStr(Instant.Edit66.Text,1)='-' then
  4106.     TimePoint:=Round(LactationLength/DaysInWeek)+7
  4107.                  +StrToInt(Instant.Edit66.Text)
  4108.    else
  4109.     TimePoint:=StrToInt(Instant.Edit66.Text);
  4110.    end;
  4111.  
  4112.   SingleRunPDF(PdfBox1,@Feeding,PdfBox1.PageWidth,PdfBox1.PageHeight,
  4113.                TimePoint,LangID);
  4114.   PdfBox1.NewPage(True);
  4115.   ModelInput(PdfBox1,PdfBox1.PageWidth,PdfBox1.PageHeight);
  4116.   PdfBox1.EndDoc;
  4117.   end;
  4118.  if PDF.CheckBox12.Checked then
  4119.   begin
  4120.    m:=0;t:=0;
  4121.    for n:=1 to 16 do
  4122.     begin
  4123.     if FeedLength[n].Start<FeedLength[n].Finish then inc(m);
  4124.     end;
  4125.    if m>0 then
  4126.     for n:=1 to m do
  4127.      begin
  4128.      PdfBox1.FileName:=FilePath+'\'+PDFFileName+' PreMix '+IntToStr(n)+'.pdf'; //premix
  4129.      PdfBox1.BeginDoc;
  4130.      PreMixpdf(PdfBox1,PdfBox1.PageWidth,PdfBox1.PageHeight,n,t,PDF.Edit1.Text);
  4131.      PdfBox1.EndDoc;
  4132.      end;
  4133.    if PreMixParlourNo>1 then
  4134.      begin
  4135.      PdfBox1.FileName:=FilePath+'\'+PDFFileName+' PreMix Parlour.pdf';
  4136.      PdfBox1.BeginDoc;
  4137.      PreMixParlourpdf(PdfBox1,PdfBox1.PageWidth,PdfBox1.PageHeight,PDF.Edit1.Text);
  4138.      PdfBox1.EndDoc;
  4139.      end;
  4140.    if PreMixRoboticNo>1 then
  4141.      begin
  4142.      PdfBox1.FileName:=FilePath+'\'+PDFFileName+' PreMix Bin 2.pdf';
  4143.      PdfBox1.BeginDoc;
  4144.      PreMixRoboticpdf(PdfBox1,PdfBox1.PageWidth,PdfBox1.PageHeight,PDF.Edit1.Text);
  4145.      PdfBox1.EndDoc;
  4146.      end;
  4147.   end;
  4148.  if PDF.CheckBox7.Checked then
  4149.   begin
  4150.   PdfBox1.Orientation:=poLandscape;
  4151.   PdfBox1.FileName:=FilePath+'\'+PDFFileName+' Diet1.pdf';
  4152.   PdfBox1.BeginDoc;
  4153.   Diet1PDF(PdfBox1,@Feeding,PdfBox1.PageWidth,PdfBox1.PageHeight);
  4154.   PdfBox1.EndDoc;
  4155.   PdfBox1.Orientation:=poPortrait;
  4156.   end;
  4157.  end;
  4158. end;
  4159.  
  4160. procedure TMain.Save1Click(Sender: TObject);
  4161. begin
  4162. Main.SpeedButton7Click(Self);
  4163. end;
  4164.  
  4165. procedure TMain.SaveAs1Click(Sender: TObject);
  4166. begin
  4167. if IMustSave then
  4168.  Main.SpeedButton7Click(Self)
  4169. else
  4170.  ShowMessage('You cannot Save until you have:'+#13#10+#13#10+'Run the model, or'
  4171.               +#13#10+'made further changes that require Saving');
  4172. end;
  4173.  
  4174. procedure TMain.Open1Click(Sender: TObject);
  4175. begin
  4176. Main.SpeedButton10Click(Self);
  4177. end;
  4178.  
  4179. procedure TMain.Optimize1Click(Sender: TObject);
  4180. begin
  4181. BatchMode:=True;
  4182. Zaoying:=True;
  4183. end;
  4184.  
  4185. procedure TMain.pH6Help11Click(Sender: TObject);
  4186. var
  4187. CallHelp: Boolean;
  4188.  
  4189. begin
  4190. HtmlHelp(0, nil, HH_CLOSE_ALL, 0);
  4191. if kgToOther=1 then
  4192.  Application.HelpFile:=DatabaseDirectory+'\pH6+.chm'
  4193. else
  4194.  Application.HelpFile:=DatabaseDirectory+'\pH6+.chm';
  4195. HH(0,0,CallHelp);
  4196. end;
  4197.  
  4198. procedure TMain.Quit1Click(Sender: TObject);
  4199. begin
  4200.   Application.Terminate;
  4201. end;
  4202.  
  4203. procedure TMain.SpeedButton4Click(Sender: TObject);
  4204. begin
  4205. FeedingStrategy.Show;
  4206. end;
  4207.  
  4208. procedure TMain.PrinterSetup1Click(Sender: TObject);
  4209. begin
  4210. PrinterSetupDialog1.Execute;
  4211. end;
  4212.  
  4213. procedure TMain.DeleteaFeed1Click(Sender: TObject);
  4214. var
  4215. t,text,text1: String;
  4216.  
  4217. begin
  4218. if DeleteFeed.ShowModal=mrOK then
  4219.  begin
  4220.  if LangID=2 then
  4221.   begin
  4222.   text:='Voulez vous supprimer';
  4223.   text1:='a partir de la base de donnees?';
  4224.   end
  4225.  else
  4226.   begin
  4227.   text:='Do you want to delete ';
  4228.   text1:=' from the database?';
  4229.   end;
  4230.  if MessageDlg(text+DeleteFeed.ComboBox2.Text+text1
  4231.                ,mtConfirmation,mbYesNoCancel,0)=mrYes then
  4232.   begin
  4233.   if DeleteFeed.ComboBox2.Text<>'' then
  4234.    begin
  4235.    FDTable1.TableName:='"Neil"."Client"';
  4236.    FDTable1.Open;
  4237.    FDTable1.First;
  4238.    while not FDTable1.Eof do
  4239.     begin
  4240.     if LangID=1 then t:= FDTable1.Fieldbyname('Forage').AsString
  4241.     else if LangID=2 then t:= FDTable1.Fieldbyname('ForageFr').AsString
  4242.     else if LangID=3 then t:= FDTable1.Fieldbyname('ForageUS').AsString
  4243.     else if LangID=4 then t:= FDTable1.Fieldbyname('ForageSp').AsString;
  4244.     if DeleteFeed.ComboBox1.Text=FDTable1.FieldByName('Type').AsString then
  4245.      if DeleteFeed.ComboBox2.Text=t then
  4246.       FDTable1.Delete;
  4247.     FDTable1.Next;
  4248.     end;
  4249.    FDTable1.Close;
  4250.    end;
  4251.   end;
  4252.  end;
  4253. DeleteFeed.ComboBox1.Text:='';
  4254. DeleteFeed.ComboBox2.Text:='';
  4255. end;
  4256.  
  4257. procedure TMain.DeleteaPreMix1Click(Sender: TObject);
  4258. var
  4259. t,text,text1: String;
  4260.  
  4261. begin
  4262. if DeletePreMix.ShowModal=mrOK then
  4263.  begin
  4264.  if LangID=2 then
  4265.   begin
  4266.   text:='Voulez vous supprimer';
  4267.   text1:='a partir de la base de donnees?';
  4268.   end
  4269.  else
  4270.   begin
  4271.   text:='Do you want to delete ';
  4272.   text1:=' from the database?';
  4273.   end;
  4274.  if MessageDlg(text+DeletePreMix.ComboBox1.Text+text1
  4275.                ,mtConfirmation,mbYesNoCancel,0)=mrYes then
  4276.   begin
  4277.   if DeletePreMix.ComboBox1.Text<>'' then
  4278.    begin
  4279.    FDTable1.TableName:='"Neil"."Blends"';
  4280.    FDTable1.Open;
  4281.    FDTable1.First;
  4282.    while not FDTable1.Eof do
  4283.     begin
  4284.     if LangID=1 then t:= FDTable1.Fieldbyname('NameEn').AsString
  4285.     else if LangID=2 then t:= FDTable1.Fieldbyname('NameFr').AsString
  4286.     else if LangID=3 then t:= FDTable1.Fieldbyname('NameUS').AsString
  4287.     else if LangID=4 then t:= FDTable1.Fieldbyname('NameSp').AsString;
  4288.     if DeletePreMix.ComboBox1.Text=t then
  4289.       FDTable1.Delete;
  4290.     FDTable1.Next;
  4291.     end;
  4292.    FDTable1.Close;
  4293.    end;
  4294.   end;
  4295.  end;
  4296. DeletePreMix.ComboBox1.Text:='';
  4297. end;
  4298.  
  4299. procedure TMain.L1Click(Sender: TObject);
  4300. const
  4301. DivideBy=1.1;
  4302.  
  4303. var
  4304. LangIDOld: Integer;
  4305. kgToOtherOld{,MJToOtherOld}: Single;
  4306.  
  4307. begin
  4308. with TLanguage.Create(nil) do
  4309.  try
  4310.  if Language.ShowModal=mrOK then
  4311.   begin
  4312.   LangIDOld:=LangID;
  4313.   kgToOtherOld:=kgToOther;
  4314.   if Language.RadioButton1.Checked then LangID:=1
  4315.    else if Language.RadioButton2.Checked then LangID:=2
  4316.    else if Language.RadioButton7.Checked then LangID:=3;
  4317.   if Language.RadioButton3.Checked then kgToOther:=1
  4318.    else kgToOther:=2.2046;
  4319.   if Language.RadioButton5.Checked then MJToOther:=1
  4320.    else MJToOther:=0.2389;
  4321.   if LangID<>LangIDOld then
  4322.    begin
  4323.    ReadLanguage;
  4324.    File1.Caption:=rTranslate.no2;
  4325.    Open1.Caption:=rTranslate.no10;
  4326.    SaveAs1.Caption:=rTranslate.no11;
  4327.    PrinterSetup1.Caption:=rTranslate.no16;
  4328.    Quit1.Caption:=rTranslate.no15;
  4329.    Maintenance1.Caption:=rTranslate.no3;
  4330.    Help1.Caption:=rTranslate.no5;
  4331.    SpeedButton1.Caption:=rTranslate.no8;
  4332.    SpeedButton4.Caption:=rTranslate.no7;
  4333.    btnRun.Caption:=rTranslate.no9+' pH6+ Dairy';
  4334.    SpeedButton10.Hint:=rTranslate.no10;
  4335.    SpeedButton7.Hint:=rTranslate.no11;
  4336.    SpeedButton5.Caption:=rTranslate.no12;
  4337.    SpeedButton6.Caption:=rTranslate.no13;
  4338.    SpeedButton8.Hint:=rTranslate.no14;
  4339.    SpeedButton3.Caption:=rTranslate.no15;
  4340.    end;
  4341.   if kgToOther>kgToOtherOld then
  4342.    begin
  4343.    Instant.Edit61.Text:=FloatToStrF(StrToFloat(Instant.Edit61.Text)*kgToOther,ffFixed,4,0);
  4344.    Instant.Edit63.Text:=FloatToStrF(StrToFloat(Instant.Edit63.Text)*kgToOther,ffFixed,3,0);
  4345.    end
  4346.   else if kgToOther<kgToOtherOld then
  4347.    begin
  4348.    Instant.Edit61.Text:=FloatToStrF(StrToFloat(Instant.Edit61.Text)/kgToOtherOld,ffFixed,3,0);
  4349.    Instant.Edit63.Text:=FloatToStrF(StrToFloat(Instant.Edit63.Text)/kgToOtherOld,ffFixed,2,0);
  4350.    end;
  4351.   FeedingStrategy.TMR_ConcLabels;
  4352.   Instant.TMRLabels;
  4353.   FeedsAdded.AddFoodLabelsFW;
  4354.   OutputF.OutformLabels;
  4355.   OutputF.DrawGraph1;
  4356.   if ActiveMDIChild=OutputF then
  4357.    begin
  4358.    Instant.Show;
  4359.    OutputF.Show;
  4360.    end;
  4361.   end;
  4362.  finally
  4363.    Free;
  4364.  end;
  4365. end;
  4366.  
  4367. procedure TMain.ReadFeedPrice;
  4368. begin
  4369. FDTable1.TableName:=' FeedPricesbyConsultant ';
  4370. FDTable1.Open;
  4371. if FDTable1.Locate('Consultant',Consultant,[]) then
  4372. else FDTable1.Locate('Consultant',1,[]);
  4373. with FDTable1 do
  4374.  begin
  4375.  FeedPrice[1]:=FieldByName('F1').AsInteger;
  4376.  FeedPrice[2]:=FieldByName('F2').AsInteger;
  4377.  FeedPrice[3]:=FieldByName('F3').AsInteger;
  4378.  FeedPrice[4]:=FieldByName('F4').AsInteger;
  4379.  FeedPrice[5]:=FieldByName('F5').AsInteger;
  4380.  FeedPrice[6]:=FieldByName('F6').AsInteger;
  4381.  FeedPrice[7]:=FieldByName('F7').AsInteger;
  4382.  FeedPrice[8]:=FieldByName('F8').AsInteger;
  4383.  FeedPrice[9]:=FieldByName('F9').AsInteger;
  4384.  FeedPrice[10]:=FieldByName('F10').AsInteger;
  4385.  FeedPrice[11]:=FieldByName('F11').AsInteger;
  4386.  FeedPrice[12]:=FieldByName('F12').AsInteger;
  4387.  FeedPrice[13]:=FieldByName('F13').AsInteger;
  4388.  FeedPrice[14]:=FieldByName('F14').AsInteger;
  4389.  FeedPrice[15]:=FieldByName('F15').AsInteger;
  4390.  FeedPrice[16]:=FieldByName('F16').AsInteger;
  4391.  FeedPrice[17]:=FieldByName('F17').AsInteger;
  4392.  FeedPrice[18]:=FieldByName('F18').AsInteger;
  4393.  FeedPrice[19]:=FieldByName('F19').AsInteger;
  4394.  FeedPrice[20]:=FieldByName('F20').AsInteger;
  4395.  FeedPrice[21]:=FieldByName('F21').AsInteger;
  4396.  FeedPrice[22]:=FieldByName('F22').AsInteger;
  4397.  FeedPrice[23]:=FieldByName('F23').AsInteger;
  4398.  FeedPrice[24]:=FieldByName('F24').AsInteger;
  4399.  FeedPrice[25]:=FieldByName('F25').AsInteger;
  4400.  FeedPrice[26]:=FieldByName('F26').AsInteger;
  4401.  FeedPrice[27]:=FieldByName('F27').AsInteger;
  4402.  FeedPrice[28]:=FieldByName('F28').AsInteger;
  4403.  FeedPrice[29]:=FieldByName('F29').AsInteger;
  4404.  FeedPrice[30]:=FieldByName('F30').AsInteger;
  4405.  FeedPrice[31]:=FieldByName('F31').AsInteger;
  4406.  FeedPrice[32]:=FieldByName('F32').AsInteger;
  4407.  FeedPrice[33]:=FieldByName('F33').AsInteger;
  4408.  FeedPrice[34]:=FieldByName('F34').AsInteger;
  4409.  FeedPrice[35]:=FieldByName('F35').AsInteger;
  4410.  FeedPrice[36]:=FieldByName('F36').AsInteger;
  4411.  FeedPrice[37]:=FieldByName('F37').AsInteger;
  4412.  FeedPrice[38]:=FieldByName('F38').AsInteger;
  4413.  FeedPrice[39]:=FieldByName('F39').AsInteger;
  4414.  FeedPrice[40]:=FieldByName('F40').AsInteger;
  4415.  FeedPrice[41]:=FieldByName('F41').AsInteger;
  4416.  FeedPrice[42]:=FieldByName('F42').AsInteger;
  4417.  FeedPrice[43]:=FieldByName('F43').AsInteger;
  4418.  FeedPrice[44]:=FieldByName('F44').AsInteger;
  4419.  FeedPrice[45]:=FieldByName('F45').AsInteger;
  4420.  FeedPrice[46]:=FieldByName('F46').AsInteger;
  4421.  FeedPrice[47]:=FieldByName('F47').AsInteger;
  4422.  FeedPrice[48]:=FieldByName('F48').AsInteger;
  4423.  FeedPrice[49]:=FieldByName('F49').AsInteger;
  4424.  FeedPrice[50]:=FieldByName('F50').AsInteger;
  4425.  FeedPrice[51]:=FieldByName('F51').AsInteger;
  4426.  FeedPrice[52]:=FieldByName('F52').AsInteger;
  4427.  FeedPrice[53]:=FieldByName('F53').AsInteger;
  4428.  FeedPrice[54]:=FieldByName('F54').AsInteger;
  4429.  FeedPrice[55]:=FieldByName('F55').AsInteger;
  4430.  FeedPrice[56]:=FieldByName('F56').AsInteger;
  4431.  FeedPrice[57]:=FieldByName('F57').AsInteger;
  4432.  FeedPrice[58]:=FieldByName('F58').AsInteger;
  4433.  FeedPrice[59]:=FieldByName('F59').AsInteger;
  4434.  FeedPrice[60]:=FieldByName('F60').AsInteger;
  4435.  FeedPrice[61]:=FieldByName('F61').AsInteger;
  4436.  FeedPrice[62]:=FieldByName('F62').AsInteger;
  4437.  FeedPrice[63]:=FieldByName('F63').AsInteger;
  4438.  FeedPrice[64]:=FieldByName('F64').AsInteger;
  4439.  FeedPrice[65]:=FieldByName('F65').AsInteger;
  4440.  FeedPrice[66]:=FieldByName('F66').AsInteger;
  4441.  FeedPrice[67]:=FieldByName('F67').AsInteger;
  4442.  FeedPrice[68]:=FieldByName('F68').AsInteger;
  4443.  FeedPrice[69]:=FieldByName('F69').AsInteger;
  4444.  FeedPrice[70]:=FieldByName('F70').AsInteger;
  4445.  FeedPrice[71]:=FieldByName('F71').AsInteger;
  4446.  FeedPrice[72]:=FieldByName('F72').AsInteger;
  4447.  FeedPrice[73]:=FieldByName('F73').AsInteger;
  4448.  FeedPrice[74]:=FieldByName('F74').AsInteger;
  4449.  FeedPrice[75]:=FieldByName('F75').AsInteger;
  4450.  FeedPrice[76]:=FieldByName('F76').AsInteger;
  4451.  FeedPrice[77]:=FieldByName('F77').AsInteger;
  4452.  FeedPrice[78]:=FieldByName('F78').AsInteger;
  4453.  FeedPrice[79]:=FieldByName('F79').AsInteger;
  4454.  FeedPrice[80]:=FieldByName('F80').AsInteger;
  4455.  FeedPrice[81]:=FieldByName('F81').AsInteger;
  4456.  FeedPrice[82]:=FieldByName('F82').AsInteger;
  4457.  FeedPrice[83]:=FieldByName('F83').AsInteger;
  4458.  FeedPrice[84]:=FieldByName('F84').AsInteger;
  4459.  FeedPrice[85]:=FieldByName('F85').AsInteger;
  4460.  FeedPrice[86]:=FieldByName('F86').AsInteger;
  4461.  FeedPrice[87]:=FieldByName('F87').AsInteger;
  4462.  FeedPrice[88]:=FieldByName('F88').AsInteger;
  4463.  FeedPrice[89]:=FieldByName('F89').AsInteger;
  4464.  FeedPrice[90]:=FieldByName('F90').AsInteger;
  4465.  FeedPrice[91]:=FieldByName('F91').AsInteger;
  4466.  FeedPrice[92]:=FieldByName('F92').AsInteger;
  4467.  FeedPrice[93]:=FieldByName('F93').AsInteger;
  4468.  FeedPrice[94]:=FieldByName('F94').AsInteger;
  4469.  FeedPrice[95]:=FieldByName('F95').AsInteger;
  4470.  FeedPrice[96]:=FieldByName('F96').AsInteger;
  4471.  FeedPrice[97]:=FieldByName('F97').AsInteger;
  4472.  FeedPrice[98]:=FieldByName('F98').AsInteger;
  4473.  FeedPrice[99]:=FieldByName('F99').AsInteger;
  4474.  FeedPrice[100]:=FieldByName('F100').AsInteger;
  4475.  FeedPrice[101]:=FieldByName('F101').AsInteger;
  4476.  FeedPrice[102]:=FieldByName('F102').AsInteger;
  4477.  FeedPrice[103]:=FieldByName('F103').AsInteger;
  4478.  FeedPrice[104]:=FieldByName('F104').AsInteger;
  4479.  FeedPrice[105]:=FieldByName('F105').AsInteger;
  4480.  FeedPrice[106]:=FieldByName('F106').AsInteger;
  4481.  FeedPrice[107]:=FieldByName('F107').AsInteger;
  4482.  FeedPrice[108]:=FieldByName('F108').AsInteger;
  4483.  FeedPrice[109]:=FieldByName('F109').AsInteger;
  4484.  FeedPrice[110]:=FieldByName('F110').AsInteger;
  4485.  FeedPrice[111]:=FieldByName('F111').AsInteger;
  4486.  FeedPrice[112]:=FieldByName('F112').AsInteger;
  4487.  FeedPrice[113]:=FieldByName('F113').AsInteger;
  4488.  FeedPrice[114]:=FieldByName('F114').AsInteger;
  4489.  FeedPrice[115]:=FieldByName('F115').AsInteger;
  4490.  FeedPrice[116]:=FieldByName('F116').AsInteger;
  4491.  FeedPrice[117]:=FieldByName('F117').AsInteger;
  4492.  FeedPrice[118]:=FieldByName('F118').AsInteger;
  4493.  FeedPrice[119]:=FieldByName('F119').AsInteger;
  4494.  FeedPrice[120]:=FieldByName('F120').AsInteger;
  4495.  FeedPrice[121]:=FieldByName('F121').AsInteger;
  4496.  FeedPrice[122]:=FieldByName('F122').AsInteger;
  4497.  FeedPrice[123]:=FieldByName('F123').AsInteger;
  4498.  FeedPrice[124]:=FieldByName('F124').AsInteger;
  4499.  FeedPrice[125]:=FieldByName('F125').AsInteger;
  4500.  FeedPrice[126]:=FieldByName('F126').AsInteger;
  4501.  FeedPrice[127]:=FieldByName('F127').AsInteger;
  4502.  FeedPrice[128]:=FieldByName('F128').AsInteger;
  4503.  FeedPrice[129]:=FieldByName('F129').AsInteger;
  4504.  FeedPrice[130]:=FieldByName('F130').AsInteger;
  4505.  FeedPrice[131]:=FieldByName('F131').AsInteger;
  4506.  FeedPrice[132]:=FieldByName('F132').AsInteger;
  4507.  FeedPrice[133]:=FieldByName('F133').AsInteger;
  4508.  FeedPrice[134]:=FieldByName('F134').AsInteger;
  4509.  FeedPrice[135]:=FieldByName('F135').AsInteger;
  4510.  FeedPrice[136]:=FieldByName('F136').AsInteger;
  4511.  FeedPrice[137]:=FieldByName('F137').AsInteger;
  4512.  FeedPrice[138]:=FieldByName('F138').AsInteger;
  4513.  FeedPrice[139]:=FieldByName('F139').AsInteger;
  4514.  FeedPrice[140]:=FieldByName('F140').AsInteger;
  4515.  FeedPrice[141]:=FieldByName('F141').AsInteger;
  4516.  FeedPrice[142]:=FieldByName('F142').AsInteger;
  4517.  FeedPrice[143]:=FieldByName('F143').AsInteger;
  4518.  FeedPrice[144]:=FieldByName('F144').AsInteger;
  4519.  FeedPrice[145]:=FieldByName('F145').AsInteger;
  4520.  FeedPrice[146]:=FieldByName('F146').AsInteger;
  4521.  FeedPrice[147]:=FieldByName('F147').AsInteger;
  4522.  FeedPrice[148]:=FieldByName('F148').AsInteger;
  4523.  FeedPrice[149]:=FieldByName('F149').AsInteger;
  4524.  FeedPrice[150]:=FieldByName('F150').AsInteger;
  4525.  FeedPrice[151]:=FieldByName('M1').AsInteger;
  4526.  FeedPrice[152]:=FieldByName('M2').AsInteger;
  4527.  FeedPrice[153]:=FieldByName('M3').AsInteger;
  4528.  FeedPrice[154]:=FieldByName('M4').AsInteger;
  4529.  FeedPrice[155]:=FieldByName('M5').AsInteger;
  4530.  FeedPrice[156]:=FieldByName('M6').AsInteger;
  4531.  FeedPrice[157]:=FieldByName('M7').AsInteger;
  4532.  FeedPrice[158]:=FieldByName('M8').AsInteger;
  4533.  FeedPrice[159]:=FieldByName('M9').AsInteger;
  4534.  FeedPrice[160]:=FieldByName('M10').AsInteger;
  4535.  FeedPrice[161]:=FieldByName('M11').AsInteger;
  4536.  FeedPrice[162]:=FieldByName('M12').AsInteger;
  4537.  FeedPrice[163]:=FieldByName('M13').AsInteger;
  4538.  FeedPrice[164]:=FieldByName('M14').AsInteger;
  4539.  FeedPrice[165]:=FieldByName('M15').AsInteger;
  4540.  FeedPrice[166]:=FieldByName('M16').AsInteger;
  4541.  FeedPrice[167]:=FieldByName('M17').AsInteger;
  4542.  FeedPrice[168]:=FieldByName('M18').AsInteger;
  4543.  FeedPrice[169]:=FieldByName('M19').AsInteger;
  4544.  FeedPrice[170]:=FieldByName('M20').AsInteger;
  4545.  FeedPrice[171]:=FieldByName('M21').AsInteger;
  4546.  FeedPrice[172]:=FieldByName('M22').AsInteger;
  4547.  FeedPrice[173]:=FieldByName('M23').AsInteger;
  4548.  FeedPrice[174]:=FieldByName('M24').AsInteger;
  4549.  FeedPrice[175]:=FieldByName('M25').AsInteger;
  4550.  FeedPrice[176]:=FieldByName('M26').AsInteger;
  4551.  FeedPrice[177]:=FieldByName('M27').AsInteger;
  4552.  FeedPrice[178]:=FieldByName('M28').AsInteger;
  4553.  FeedPrice[179]:=FieldByName('M29').AsInteger;
  4554.  FeedPrice[180]:=FieldByName('M30').AsInteger;
  4555.  FeedPrice[181]:=FieldByName('M31').AsInteger;
  4556.  FeedPrice[182]:=FieldByName('M32').AsInteger;
  4557.  FeedPrice[183]:=FieldByName('M33').AsInteger;
  4558.  FeedPrice[184]:=FieldByName('M34').AsInteger;
  4559.  FeedPrice[185]:=FieldByName('M35').AsInteger;
  4560.  FeedPrice[186]:=FieldByName('M36').AsInteger;
  4561.  FeedPrice[187]:=FieldByName('M37').AsInteger;
  4562.  FeedPrice[188]:=FieldByName('M38').AsInteger;
  4563.  FeedPrice[189]:=FieldByName('M39').AsInteger;
  4564.  FeedPrice[190]:=FieldByName('M40').AsInteger;
  4565.  FeedPrice[191]:=FieldByName('M41').AsInteger;
  4566.  FeedPrice[192]:=FieldByName('M42').AsInteger;
  4567.  FeedPrice[193]:=FieldByName('M43').AsInteger;
  4568.  FeedPrice[194]:=FieldByName('M44').AsInteger;
  4569.  FeedPrice[195]:=FieldByName('M45').AsInteger;
  4570.  FeedPrice[196]:=FieldByName('M46').AsInteger;
  4571.  FeedPrice[197]:=FieldByName('M47').AsInteger;
  4572.  FeedPrice[198]:=FieldByName('M48').AsInteger;
  4573.  FeedPrice[199]:=FieldByName('M49').AsInteger;
  4574.  FeedPrice[200]:=FieldByName('M50').AsInteger;
  4575.  FeedPrice[201]:=FieldByName('G1').AsInteger;
  4576.  FeedPrice[202]:=FieldByName('G2').AsInteger;
  4577.  FeedPrice[203]:=FieldByName('G3').AsInteger;
  4578.  FeedPrice[204]:=FieldByName('G4').AsInteger;
  4579.  FeedPrice[205]:=FieldByName('G5').AsInteger;
  4580.  FeedPrice[206]:=FieldByName('G6').AsInteger;
  4581.  FeedPrice[207]:=FieldByName('G7').AsInteger;
  4582.  FeedPrice[208]:=FieldByName('G8').AsInteger;
  4583.  FeedPrice[209]:=FieldByName('G9').AsInteger;
  4584.  FeedPrice[210]:=FieldByName('G10').AsInteger;
  4585.  FeedPrice[211]:=FieldByName('G11').AsInteger;
  4586.  FeedPrice[212]:=FieldByName('G12').AsInteger;
  4587.  FeedPrice[213]:=FieldByName('G13').AsInteger;
  4588.  FeedPrice[214]:=FieldByName('G14').AsInteger;
  4589.  FeedPrice[215]:=FieldByName('G15').AsInteger;
  4590.  FeedPrice[216]:=FieldByName('G16').AsInteger;
  4591.  FeedPrice[217]:=FieldByName('G17').AsInteger;
  4592.  FeedPrice[218]:=FieldByName('G18').AsInteger;
  4593.  FeedPrice[219]:=FieldByName('G19').AsInteger;
  4594.  FeedPrice[220]:=FieldByName('G20').AsInteger;
  4595.  FeedPrice[221]:=FieldByName('G21').AsInteger;
  4596.  FeedPrice[222]:=FieldByName('G22').AsInteger;
  4597.  FeedPrice[223]:=FieldByName('G23').AsInteger;
  4598.  FeedPrice[224]:=FieldByName('G24').AsInteger;
  4599.  FeedPrice[225]:=FieldByName('G25').AsInteger;
  4600.  FeedPrice[226]:=FieldByName('G26').AsInteger;
  4601.  FeedPrice[227]:=FieldByName('G27').AsInteger;
  4602.  FeedPrice[228]:=FieldByName('G28').AsInteger;
  4603.  FeedPrice[229]:=FieldByName('G29').AsInteger;
  4604.  FeedPrice[230]:=FieldByName('G30').AsInteger;
  4605.  FeedPrice[231]:=FieldByName('G31').AsInteger;
  4606.  FeedPrice[232]:=FieldByName('G32').AsInteger;
  4607.  FeedPrice[233]:=FieldByName('G33').AsInteger;
  4608.  FeedPrice[234]:=FieldByName('G34').AsInteger;
  4609.  FeedPrice[235]:=FieldByName('G35').AsInteger;
  4610.  FeedPrice[236]:=FieldByName('G36').AsInteger;
  4611.  FeedPrice[237]:=FieldByName('G37').AsInteger;
  4612.  FeedPrice[238]:=FieldByName('G38').AsInteger;
  4613.  FeedPrice[239]:=FieldByName('G39').AsInteger;
  4614.  FeedPrice[240]:=FieldByName('G40').AsInteger;
  4615.  FeedPrice[241]:=FieldByName('G41').AsInteger;
  4616.  FeedPrice[242]:=FieldByName('G42').AsInteger;
  4617.  FeedPrice[243]:=FieldByName('G43').AsInteger;
  4618.  FeedPrice[244]:=FieldByName('G44').AsInteger;
  4619.  FeedPrice[245]:=FieldByName('G45').AsInteger;
  4620.  FeedPrice[246]:=FieldByName('G46').AsInteger;
  4621.  FeedPrice[247]:=FieldByName('G47').AsInteger;
  4622.  FeedPrice[248]:=FieldByName('G48').AsInteger;
  4623.  FeedPrice[249]:=FieldByName('G49').AsInteger;
  4624.  FeedPrice[250]:=FieldByName('G50').AsInteger;
  4625.  end;
  4626. FDTable1.Close;
  4627. end;
  4628.  
  4629. procedure TMain.ReadLanguage;
  4630. begin
  4631. FDTable1.TableName:=' EnFrUSSp ';
  4632. FDTable1.Open;
  4633. FDTable1.First;
  4634. while not FDTable1.Eof do
  4635.   begin
  4636.   if LangID=FDTable1.Fieldbyname('Language').AsInteger then
  4637.    begin
  4638.    with FDTable1 do
  4639.     begin
  4640.     rTranslate.no1:= FieldByName('1').AsString;
  4641.     rTranslate.no2:= FieldByName('2').AsString;
  4642.     rTranslate.no3:= FieldByName('3').AsString;
  4643.     rTranslate.no4:= FieldByName('4').AsString;
  4644.     rTranslate.no5:= FieldByName('5').AsString;
  4645.     rTranslate.no6:= FieldByName('6').AsString;
  4646.     rTranslate.no7:= FieldByName('7').AsString;
  4647.     rTranslate.no8:= FieldByName('8').AsString;
  4648.     rTranslate.no9:= FieldByName('9').AsString;
  4649.     rTranslate.no10:= FieldByName('10').AsString;
  4650.     rTranslate.no11:= FieldByName('11').AsString;
  4651.     rTranslate.no12:= FieldByName('12').AsString;
  4652.     rTranslate.no13:= FieldByName('13').AsString;
  4653.     rTranslate.no14:= FieldByName('14').AsString;
  4654.     rTranslate.no15:= FieldByName('15').AsString;
  4655.     rTranslate.no16:= FieldByName('16').AsString;
  4656.     rTranslate.no17:= FieldByName('17').AsString;
  4657.     rTranslate.no18:= FieldByName('18').AsString;
  4658.     rTranslate.no19:= FieldByName('19').AsString;
  4659.     rTranslate.no20:= FieldByName('20').AsString;
  4660.     rTranslate.no21:= FieldByName('21').AsString;
  4661.     rTranslate.no22:= FieldByName('22').AsString;
  4662.     rTranslate.no23:= FieldByName('23').AsString;
  4663.     rTranslate.no24:= FieldByName('24').AsString;
  4664.     rTranslate.no25:= FieldByName('25').AsString;
  4665.     rTranslate.no26:= FieldByName('26').AsString;
  4666.     rTranslate.no27:= FieldByName('27').AsString;
  4667.     rTranslate.no28:= FieldByName('28').AsString;
  4668.     rTranslate.no29:= FieldByName('29').AsString;
  4669.     rTranslate.no30:= FieldByName('30').AsString;
  4670.     rTranslate.no31:= FieldByName('31').AsString;
  4671.     rTranslate.no32:= FieldByName('32').AsString;
  4672.     rTranslate.no33:= FieldByName('33').AsString;
  4673.     rTranslate.no34:= FieldByName('34').AsString;
  4674.     rTranslate.no35:= FieldByName('35').AsString;
  4675.     rTranslate.no36:= FieldByName('36').AsString;
  4676.     rTranslate.no37:= FieldByName('37').AsString;
  4677.     rTranslate.no38:= FieldByName('38').AsString;
  4678.     rTranslate.no39:= FieldByName('39').AsString;
  4679.     rTranslate.no40:= FieldByName('40').AsString;
  4680.     rTranslate.no41:= FieldByName('41').AsString;
  4681.     rTranslate.no42:= FieldByName('42').AsString;
  4682.     rTranslate.no43:= FieldByName('43').AsString;
  4683.     rTranslate.no44:= FieldByName('44').AsString;
  4684.     rTranslate.no45:= FieldByName('45').AsString;
  4685.     rTranslate.no46:= FieldByName('46').AsString;
  4686.     rTranslate.no47:= FieldByName('47').AsString;
  4687.     rTranslate.no48:= FieldByName('48').AsString;
  4688.     rTranslate.no49:= FieldByName('49').AsString;
  4689.     rTranslate.no50:= FieldByName('50').AsString;
  4690.     rTranslate.no51:= FieldByName('51').AsString;
  4691.     rTranslate.no52:= FieldByName('52').AsString;
  4692.     rTranslate.no53:= FieldByName('53').AsString;
  4693.     rTranslate.no54:= FieldByName('54').AsString;
  4694.     rTranslate.no55:= FieldByName('55').AsString;
  4695.     rTranslate.no56:= FieldByName('56').AsString;
  4696.     rTranslate.no57:= FieldByName('57').AsString;
  4697.     rTranslate.no58:= FieldByName('58').AsString;
  4698.     rTranslate.no59:= FieldByName('59').AsString;
  4699.     rTranslate.no60:= FieldByName('60').AsString;
  4700.     rTranslate.no61:= FieldByName('61').AsString;
  4701.     rTranslate.no62:= FieldByName('62').AsString;
  4702.     rTranslate.no63:= FieldByName('63').AsString;
  4703.     rTranslate.no64:= FieldByName('64').AsString;
  4704.     rTranslate.no65:= FieldByName('65').AsString;
  4705.     rTranslate.no66:= FieldByName('66').AsString;
  4706.     rTranslate.no67:= FieldByName('67').AsString;
  4707.     rTranslate.no68:= FieldByName('68').AsString;
  4708.     rTranslate.no69:= FieldByName('69').AsString;
  4709.     rTranslate.no70:= FieldByName('70').AsString;
  4710.     rTranslate.no71:= FieldByName('71').AsString;
  4711.     rTranslate.no72:= FieldByName('72').AsString;
  4712.     rTranslate.no73:= FieldByName('73').AsString;
  4713.     rTranslate.no74:= FieldByName('74').AsString;
  4714.     rTranslate.no75:= FieldByName('75').AsString;
  4715.     rTranslate.no76:= FieldByName('76').AsString;
  4716.     rTranslate.no77:= FieldByName('77').AsString;
  4717.     rTranslate.no78:= FieldByName('78').AsString;
  4718.     rTranslate.no79:= FieldByName('79').AsString;
  4719.     rTranslate.no80:= FieldByName('80').AsString;
  4720.     rTranslate.no81:= FieldByName('81').AsString;
  4721.     rTranslate.no82:= FieldByName('82').AsString;
  4722.     rTranslate.no83:= FieldByName('83').AsString;
  4723.     rTranslate.no84:= FieldByName('84').AsString;
  4724.     rTranslate.no85:= FieldByName('85').AsString;
  4725.     rTranslate.no86:= FieldByName('86').AsString;
  4726.     rTranslate.no87:= FieldByName('87').AsString;
  4727.     rTranslate.no88:= FieldByName('88').AsString;
  4728.     rTranslate.no89:= FieldByName('89').AsString;
  4729.     rTranslate.no90:= FieldByName('90').AsString;
  4730.     rTranslate.no91:= FieldByName('91').AsString;
  4731.     rTranslate.no92:= FieldByName('92').AsString;
  4732.     rTranslate.no93:= FieldByName('93').AsString;
  4733.     rTranslate.no94:= FieldByName('94').AsString;
  4734.     rTranslate.no95:= FieldByName('95').AsString;
  4735.     rTranslate.no96:= FieldByName('96').AsString;
  4736.     rTranslate.no97:= FieldByName('97').AsString;
  4737.     rTranslate.no98:= FieldByName('98').AsString;
  4738.     rTranslate.no99:= FieldByName('99').AsString;
  4739.     rTranslate.no100:= FieldByName('100').AsString;
  4740.     rTranslate.no101:= FieldByName('101').AsString;
  4741.     rTranslate.no102:= FieldByName('102').AsString;
  4742.     rTranslate.no103:= FieldByName('103').AsString;
  4743.     rTranslate.no104:= FieldByName('104').AsString;
  4744.     rTranslate.no105:= FieldByName('105').AsString;
  4745.     rTranslate.no106:= FieldByName('106').AsString;
  4746.     rTranslate.no107:= FieldByName('107').AsString;
  4747.     rTranslate.no108:= FieldByName('108').AsString;
  4748.     rTranslate.no109:= FieldByName('109').AsString;
  4749.     rTranslate.no110:= FieldByName('110').AsString;
  4750.     rTranslate.no111:= FieldByName('111').AsString;
  4751.     rTranslate.no112:= FieldByName('112').AsString;
  4752.     rTranslate.no113:= FieldByName('113').AsString;
  4753.     rTranslate.no114:= FieldByName('114').AsString;
  4754.     rTranslate.no115:= FieldByName('115').AsString;
  4755.     rTranslate.no116:= FieldByName('116').AsString;
  4756.     rTranslate.no117:= FieldByName('117').AsString;
  4757.     rTranslate.no118:= FieldByName('118').AsString;
  4758.     rTranslate.no119:= FieldByName('119').AsString;
  4759.     rTranslate.no120:= FieldByName('120').AsString;
  4760.     rTranslate.no121:= FieldByName('121').AsString;
  4761.     rTranslate.no122:= FieldByName('122').AsString;
  4762.     rTranslate.no123:= FieldByName('123').AsString;
  4763.     rTranslate.no124:= FieldByName('124').AsString;
  4764.     rTranslate.no125:= FieldByName('125').AsString;
  4765.     rTranslate.no126:= FieldByName('126').AsString;
  4766.     rTranslate.no127:= FieldByName('127').AsString;
  4767.     rTranslate.no128:= FieldByName('128').AsString;
  4768.     rTranslate.no129:= FieldByName('129').AsString;
  4769.     rTranslate.no130:= FieldByName('130').AsString;
  4770.     rTranslate.no131:= FieldByName('131').AsString;
  4771.     rTranslate.no132:= FieldByName('132').AsString;
  4772.     rTranslate.no133:= FieldByName('133').AsString;
  4773.     rTranslate.no134:= FieldByName('134').AsString;
  4774.     rTranslate.no135:= FieldByName('135').AsString;
  4775.     rTranslate.no136:= FieldByName('136').AsString;
  4776.     rTranslate.no137:= FieldByName('137').AsString;
  4777.     rTranslate.no138:= FieldByName('138').AsString;
  4778.     rTranslate.no139:= FieldByName('139').AsString;
  4779.     rTranslate.no140:= FieldByName('140').AsString;
  4780.     rTranslate.no141:= FieldByName('141').AsString;
  4781.     rTranslate.no142:= FieldByName('142').AsString;
  4782.     rTranslate.no143:= FieldByName('143').AsString;
  4783.     rTranslate.no144:= FieldByName('144').AsString;
  4784.     rTranslate.no145:= FieldByName('145').AsString;
  4785.     rTranslate.no146:= FieldByName('146').AsString;
  4786.     rTranslate.no147:= FieldByName('147').AsString;
  4787.     rTranslate.no148:= FieldByName('148').AsString;
  4788.     rTranslate.no149:= FieldByName('149').AsString;
  4789.     rTranslate.no150:= FieldByName('150').AsString;
  4790.     rTranslate.no151:= FieldByName('151').AsString;
  4791.     rTranslate.no152:= FieldByName('152').AsString;
  4792.     rTranslate.no153:= FieldByName('153').AsString;
  4793.     rTranslate.no154:= FieldByName('154').AsString;
  4794.     rTranslate.no155:= FieldByName('155').AsString;
  4795.     rTranslate.no156:= FieldByName('156').AsString;
  4796.     rTranslate.no157:= FieldByName('157').AsString;
  4797.     rTranslate.no158:= FieldByName('158').AsString;
  4798.     rTranslate.no159:= FieldByName('159').AsString;
  4799.     rTranslate.no160:= FieldByName('160').AsString;
  4800.     rTranslate.no161:= FieldByName('161').AsString;
  4801.     rTranslate.no162:= FieldByName('162').AsString;
  4802.     rTranslate.no163:= FieldByName('163').AsString;
  4803.     rTranslate.no164:= FieldByName('164').AsString;
  4804.     rTranslate.no165:= FieldByName('165').AsString;
  4805.     rTranslate.no166:= FieldByName('166').AsString;
  4806.     rTranslate.no167:= FieldByName('167').AsString;
  4807.     rTranslate.no168:= FieldByName('168').AsString;
  4808.     rTranslate.no169:= FieldByName('169').AsString;
  4809.     rTranslate.no170:= FieldByName('170').AsString;
  4810.     rTranslate.no171:= FieldByName('171').AsString;
  4811.     rTranslate.no172:= FieldByName('172').AsString;
  4812.     rTranslate.no173:= FieldByName('173').AsString;
  4813.     rTranslate.no174:= FieldByName('174').AsString;
  4814.     rTranslate.no175:= FieldByName('175').AsString;
  4815.     rTranslate.no176:= FieldByName('176').AsString;
  4816.     rTranslate.no177:= FieldByName('177').AsString;
  4817.     rTranslate.no178:= FieldByName('178').AsString;
  4818.     rTranslate.no179:= FieldByName('179').AsString;
  4819.     rTranslate.no180:= FieldByName('180').AsString;
  4820.     rTranslate.no181:= FieldByName('181').AsString;
  4821.     rTranslate.no182:= FieldByName('182').AsString;
  4822.     rTranslate.no183:= FieldByName('183').AsString;
  4823.     rTranslate.no185:= FieldByName('185').AsString;
  4824.     rTranslate.no188:= FieldByName('188').AsString;
  4825.     rTranslate.no189:= FieldByName('189').AsString;
  4826.     rTranslate.no190:= FieldByName('190').AsString;
  4827.     rTranslate.no191:= FieldByName('191').AsString;
  4828.     rTranslate.no192:= FieldByName('192').AsString;
  4829.     rTranslate.no193:= FieldByName('193').AsString;
  4830.     rTranslate.no194:= FieldByName('194').AsString;
  4831.     rTranslate.no195:= FieldByName('195').AsString;
  4832.     rTranslate.no196:= FieldByName('196').AsString;
  4833.     rTranslate.no197:= FieldByName('197').AsString;
  4834.     rTranslate.no198:= FieldByName('198').AsString;
  4835.     rTranslate.no199:= FieldByName('199').AsString;
  4836.     rTranslate.no200:= FieldByName('200').AsString;
  4837.     rTranslate.no201:= FieldByName('201').AsString;
  4838.     rTranslate.no202:= FieldByName('202').AsString;
  4839.     rTranslate.no203:= FieldByName('203').AsString;
  4840.     rTranslate.no204:= FieldByName('204').AsString;
  4841.     rTranslate.no205:= FieldByName('205').AsString;
  4842.     rTranslate.no206:= FieldByName('206').AsString;
  4843.     rTranslate.no207:= FieldByName('207').AsString;
  4844.     rTranslate.no208:= FieldByName('208').AsString;
  4845.     rTranslate.no209:= FieldByName('209').AsString;
  4846.     rTranslate.no210:= FieldByName('210').AsString;
  4847.     rTranslate.no211:= FieldByName('211').AsString;
  4848.     rTranslate.no212:= FieldByName('212').AsString;
  4849.     rTranslate.no213:= FieldByName('213').AsString;
  4850.     rTranslate.no214:= FieldByName('214').AsString;
  4851.     rTranslate.no215:= FieldByName('215').AsString;
  4852.     rTranslate.no216:= FieldByName('216').AsString;
  4853.     rTranslate.no217:= FieldByName('217').AsString;
  4854.     rTranslate.no218:= FieldByName('218').AsString;
  4855.     rTranslate.no219:= FieldByName('219').AsString;
  4856.     rTranslate.no220:= FieldByName('220').AsString;
  4857.     rTranslate.no221:= FieldByName('221').AsString;
  4858.     rTranslate.no222:= FieldByName('222').AsString;
  4859.     rTranslate.no223:= FieldByName('223').AsString;
  4860.     rTranslate.no224:= FieldByName('224').AsString;
  4861.     rTranslate.no225:= FieldByName('225').AsString;
  4862.     rTranslate.no226:= FieldByName('226').AsString;
  4863.     rTranslate.no227:= FieldByName('227').AsString;
  4864.     rTranslate.no228:= FieldByName('228').AsString;
  4865.     rTranslate.no229:= FieldByName('229').AsString;
  4866.     rTranslate.no230:= FieldByName('230').AsString;
  4867.     rTranslate.no231:= FieldByName('231').AsString;
  4868.     rTranslate.no232:= FieldByName('232').AsString;
  4869.     rTranslate.no233:= FieldByName('233').AsString;
  4870.     rTranslate.no234:= FieldByName('234').AsString;
  4871.     rTranslate.no235:= FieldByName('235').AsString;
  4872.     rTranslate.no236:= FieldByName('236').AsString;
  4873.     rTranslate.no237:= FieldByName('237').AsString;
  4874.     rTranslate.no238:= FieldByName('238').AsString;
  4875.     rTranslate.no239:= FieldByName('239').AsString;
  4876.     rTranslate.no240:= FieldByName('240').AsString;
  4877.     rTranslate.no241:= FieldByName('241').AsString;
  4878.     rTranslate.no242:= FieldByName('242').AsString;
  4879.     rTranslate.no243:= FieldByName('243').AsString;
  4880.     rTranslate.no244:= FieldByName('244').AsString;
  4881.     rTranslate.no245:= FieldByName('245').AsString;
  4882.     rTranslate.no246:= FieldByName('246').AsString;
  4883.     rTranslate.no247:= FieldByName('247').AsString;
  4884.     rTranslate.no248:= FieldByName('248').AsString;
  4885.     rTranslate.no249:= FieldByName('249').AsString;
  4886.     rTranslate.no250:= FieldByName('250').AsString;
  4887.     rTranslate.no251:= FieldByName('251').AsString;
  4888.     rTranslate.no252:= FieldByName('252').AsString;
  4889.     rTranslate.no253:= FieldByName('253').AsString;
  4890.     rTranslate.no254:= FieldByName('254').AsString;
  4891.     rTranslate.no255:= FieldByName('255').AsString;
  4892.     rTranslate.no256:= FieldByName('256').AsString;
  4893.     rTranslate.no257:= FieldByName('257').AsString;
  4894.     rTranslate.no258:= FieldByName('258').AsString;
  4895.     rTranslate.no259:= FieldByName('259').AsString;
  4896.     rTranslate.no260:= FieldByName('260').AsString;
  4897.     rTranslate.no261:= FieldByName('261').AsString;
  4898.     rTranslate.no262:= FieldByName('262').AsString;
  4899.     rTranslate.no263:= FieldByName('263').AsString;
  4900.     rTranslate.no264:= FieldByName('264').AsString;
  4901.     rTranslate.no265:= FieldByName('265').AsString;
  4902.     rTranslate.no266:= FieldByName('266').AsString;
  4903.     rTranslate.no267:= FieldByName('267').AsString;
  4904.     rTranslate.no268:= FieldByName('268').AsString;
  4905.     rTranslate.no269:= FieldByName('269').AsString;
  4906.     rTranslate.no270:= FieldByName('270').AsString;
  4907.     rTranslate.no271:= FieldByName('271').AsString;
  4908.     rTranslate.no272:= FieldByName('272').AsString;
  4909.     rTranslate.no273:= FieldByName('273').AsString;
  4910.     rTranslate.no274:= FieldByName('274').AsString;
  4911.     rTranslate.no275:= FieldByName('275').AsString;
  4912.     rTranslate.no276:= FieldByName('276').AsString;
  4913.     rTranslate.no277:= FieldByName('277').AsString;
  4914.     rTranslate.no278:= FieldByName('278').AsString;
  4915.     rTranslate.no279:= FieldByName('279').AsString;
  4916.     rTranslate.no280:= FieldByName('280').AsString;
  4917.     rTranslate.no281:= FieldByName('281').AsString;
  4918.     rTranslate.no282:= FieldByName('282').AsString;
  4919.     rTranslate.no283:= FieldByName('283').AsString;
  4920.     rTranslate.no284:= FieldByName('284').AsString;
  4921.     rTranslate.no285:= FieldByName('285').AsString;
  4922.     rTranslate.no286:= FieldByName('286').AsString;
  4923.     rTranslate.no287:= FieldByName('287').AsString;
  4924.     rTranslate.no288:= FieldByName('288').AsString;
  4925.     rTranslate.no289:= FieldByName('289').AsString;
  4926.     rTranslate.no290:= FieldByName('290').AsString;
  4927.     rTranslate.no291:= FieldByName('291').AsString;
  4928.     end;
  4929.    end;
  4930.   FDTable1.Next
  4931.   end;
  4932. FDTable1.Close;
  4933. end;
  4934.  
  4935. procedure TMain.RestrictDB1Click(Sender: TObject);
  4936. begin
  4937. {if (SavingResults) or (DBNotConnected=1) then
  4938.  begin
  4939.  ShowMessage('You cannot alter the period in which you select data as you have results to save.'
  4940.              +#10#13+'Close pH6+ Dairy down, open pH6+ Dairy and then change the period of selecting data.');
  4941.  end
  4942. else }if not DBConnected then
  4943.  begin
  4944.  ShowMessage('No internet connection!');
  4945.  end
  4946. else if RestrictDBto.ShowModal=mrOK then
  4947.  begin
  4948.  if (SavingResults) or (DBNotConnected=1) then
  4949.   begin
  4950.   SavingData:=True;
  4951.   SpeedButton3Click(Self);
  4952.   SavingResults:=False; SavingData:=False;
  4953.   end;
  4954.  UpdateYesNo:=True;
  4955.  SetUpDBFormulation;
  4956.  SetUpDBResults;
  4957.  SetUpDBClientFeeds;
  4958.  SetUpDBFarmer;
  4959.  SetUpDBPreMixes;
  4960.  Welcome.LoadFarmersData;
  4961.  OldFormulationHigh:=FormulationHigh;
  4962.  OldResultsHigh:=ResultsHigh;
  4963.  OldClientFeedsHigh:=ClientFeedsHigh;
  4964.  OldFarmerHigh:=FarmerHigh;
  4965.  OldPreMixFeedsHigh:=PreMixFeedsHigh;
  4966.  UpdateYesNo:=False;
  4967.  end;
  4968. end;
  4969.  
  4970. procedure TMain.ViewProtein1Click(Sender: TObject);
  4971. begin
  4972. if not Assigned(ProteinUsed) then
  4973.  ProteinUsed:=TProteinUsed.Create(Self);
  4974. ProteinUsed.Show;
  4975. end;
  4976.  
  4977. procedure TMain.WhatIf2Click(Sender: TObject);
  4978. begin
  4979. if not Assigned(WhatIfForm) then
  4980.  Application.CreateForm(TWhatIfForm, WhatIfForm);
  4981. if WhatIfBoolean then
  4982.  begin
  4983.  WhatIfBoolean:=False;
  4984.  WhatIf2.Checked:=False;
  4985.  WhatIfForm.Close;
  4986.  WhatIfForm.WhatIfOutputs(3);
  4987.  WhatIfForm.WhatIfOutputs(2);
  4988.  WhatIfForm.WhatIfOutputs(1);
  4989.  end
  4990. else
  4991.  begin
  4992.  WhatIfBoolean:=True;
  4993.  WhatIf2.Checked:=True;
  4994.  WhatIfNumber:=1;
  4995.  WhatIfForm.CheckBox2.Checked:=False;
  4996.  WhatIfForm.CheckBox3.Checked:=False;
  4997.  end;
  4998. end;
  4999.  
  5000. procedure TMain.ViewEnergy1Click(Sender: TObject);
  5001. begin
  5002. EnergyUsed:=TEnergyUsed.Create(Self);
  5003. EnergyUsed.Show;
  5004. end;
  5005.  
  5006. procedure TMain.ViewMGP1Click(Sender: TObject);
  5007. var
  5008. crDefault: TCursor;
  5009.  
  5010. begin
  5011. crDefault:=Screen.Cursor;
  5012. Screen.Cursor:=crHourGlass;
  5013. MGPUsed := TMGPUsed.Create(self);
  5014. try
  5015.   MGPUsed.Show;
  5016. finally
  5017. //  MGPUsed.Free;
  5018.   Screen.Cursor:=crDefault;
  5019. end;//MGPUsed.Show;
  5020. end;
  5021.  
  5022. procedure TMain.NewFarmer1Click(Sender: TObject);
  5023. begin
  5024. Welcome.Show;
  5025. end;
  5026.  
  5027. procedure TMain.FormDestroy(Sender: TObject);
  5028. begin
  5029. WriteIniFile;
  5030. end;
  5031.  
  5032. procedure TMain.WriteIniFile;
  5033. var
  5034.   IniFile  : TIniFile;
  5035.  
  5036. begin
  5037. if not Administrator then
  5038.  begin
  5039.  if DBConnected and RunpH6 then
  5040.   DBNotConnected:=0
  5041.  else
  5042.   DBNotConnected:=1;
  5043.  EnDeCryptFile(DatabaseDirectory+'\'+BeefOrCow+' CD.ini');
  5044.  IniFile := TIniFile.Create(DatabaseDirectory+'\'+BeefOrCow+' CD.ini');//ChangeFileExt(Application.ExeName,'.ini'));
  5045.  with IniFile do
  5046.   begin
  5047.   WriteInteger('Language','LangID',LangID);
  5048.   WriteFloat('Language','kgToOther',kgToOther);
  5049.   WriteFloat('Language','MJToOther',MJToOther);
  5050.   WriteBool('Maintenance','Batch',BatchMode);
  5051.   WriteBool('Maintenance','ShowAFFile',ShowAFFile);
  5052.   WriteInteger('Maintenance','MasterFeedsHigh',MasterFeedsHigh);
  5053.   WriteInteger('Maintenance','ClientFeedsHigh',ClientFeedsHigh);
  5054.   WriteInteger('Maintenance','PreMixFeedsHigh',PreMixFeedsHigh);
  5055.   WriteInteger('Maintenance','FormulationHigh',FormulationHigh);
  5056.   WriteInteger('Maintenance','FarmerHigh',FarmerHigh);
  5057.   WriteInteger('Maintenance','ResultsHigh',ResultsHigh);
  5058.   WriteBool('Maintenance','DBResultsChange',DBResultsChange);
  5059.   WriteInteger('Maintenance','DBNotConnected',DBNotConnected);
  5060.   WriteFloat('Maintenance','DateLastUsed',DateLastUsed);
  5061.   WriteString('Maintenance','User',User);
  5062.   WriteString('Maintenance','Password',Password);
  5063.   WriteString('Maintenance','UserName',User_Name);
  5064.   WriteString('Maintenance','PW',PW);
  5065.   WriteBool('Maintenance','ProgramCrashed',False);
  5066.   WriteInteger('Maintenance','OldClientFeedsHigh',OldClientFeedsHigh);
  5067.   WriteInteger('Maintenance','OldMasterFeedsHigh',OldMasterFeedsHigh);
  5068.   WriteInteger('Maintenance','OldPreMixFeedsHigh',OldPreMixFeedsHigh);
  5069.   WriteInteger('Maintenance','OldFarmerHigh',OldFarmerHigh);
  5070.   WriteInteger('Maintenance','OldFormulationHigh',OldFormulationHigh);
  5071.   WriteInteger('Maintenance','OldResultsHigh',OldResultsHigh);
  5072.   WriteFloat('Maintenance','ForagefNDFfactor',ForagefNDFfactor);
  5073.   WriteInteger('Maintenance','MineralsHigh',MineralsHigh);
  5074.   WriteString('Maintenance','DateStarted',DateStarted);
  5075.   WriteString('Maintenance','DateChosenToRestrictDB',DateChosenToRestrictDB);
  5076.   WriteInteger('Maintenance','DifferentHDNo',DifferentHDNo);
  5077.   WriteInteger('Maintenance','HighFormulationPos',HighFormulationPos);
  5078.   WriteInteger('Maintenance','HighFormulationNeg',HighFormulationNeg);
  5079.   WriteInteger('Maintenance','HighResultsPos',HighResultsPos);
  5080.   WriteInteger('Maintenance','HighResultsNeg',HighResultsNeg);
  5081.   WriteInteger('Maintenance','HighClientNeg',HighClientNeg);
  5082.   WriteString('Maintenance','DateChosenToRestrictDBPM',DateChosenToRestrictDBPM);
  5083.   WriteInteger('Maintenance','HighPreMixesPos',HighPreMixesPos);
  5084.   WriteInteger('Maintenance','HighPreMixesNeg',HighPreMixesNeg);
  5085.   WriteInteger('Maintenance','YearChosenToRestrictDBFarmer',YearChosenToRestrictDBFarmer);
  5086.   WriteFloat('Maintenance','AccessServer',AccessServer);
  5087.   WriteString('Maintenance','WCCountry',WCCountry);
  5088.   WriteString('Maintenance','WCCurrency',WCCurrency);
  5089.   WriteString('Maintenance','WCAbbrev',WCAbbrev);
  5090.   WriteString('Maintenance','WCISO',WCISO);
  5091.   WriteString('Maintenance','WCCent',WCCent);
  5092.   WriteInteger('Maintenance','WCFraction',WCFraction);
  5093.   end;
  5094.  IniFile.Free;
  5095.  EnDeCryptFile(DatabaseDirectory+'\'+BeefOrCow+' CD.ini');
  5096.  
  5097.  if FileExists(DatabaseDirectory+'\'+BeefOrCow+' CD.ini') then
  5098.   CopyFile(PWideChar(DatabaseDirectory+'\'+BeefOrCow+' CD.ini'),PWideChar(GetDocuments+'\reg_pH6+.ph6'),False);
  5099.  end;
  5100. end;
  5101.  
  5102.  
  5103. procedure TMain.FromDatabase1Click(Sender: TObject);
  5104. var
  5105. crDefault: TCursor;
  5106. TempDBNotConnected: Integer;
  5107.  
  5108. begin
  5109. crDefault:=Screen.Cursor;
  5110. Screen.Cursor:=crHourGlass;
  5111. if FDConnection1.Ping then
  5112.  begin
  5113.  TempDBNotConnected:=DBNotConnected;
  5114.  DBNotConnected:=0;
  5115.  UpdateYesNo:=True;
  5116.  FDConnection1.Connected:=True;
  5117.  SetUpDBMasterFeeds;
  5118.  SetUpDBClientFeeds;
  5119.  SetUpDBPreMixes;
  5120.  SetUpDBFarmer;
  5121.  SetUpDBFormulation;
  5122.  SetUpDBResults;
  5123.  SetUpDBFeedLabels;
  5124.  UpdateYesNo:=False;
  5125.  FDConnection1.Connected:=False;
  5126.  Welcome.LoadFarmersData;
  5127.  Instant.LoadMainData;
  5128.  FeedingStrategy.LoadComboData;
  5129.  FeedingStrategy.LoadLiquidFeeds;
  5130.  DBNotConnected:=TempDBNotConnected;
  5131.  end
  5132. else
  5133.  ShowMessage('No internet connection!');
  5134. Screen.Cursor:=crDefault;
  5135. end;
  5136.  
  5137. procedure TMain.ModelOptions1Click(Sender: TObject);
  5138. begin
  5139. with TOptions.Create(nil) do
  5140.  try
  5141.  if Options.ShowModal=mrOK then
  5142.   begin
  5143.   if Options.CheckBox3.Checked=True then version1_01_16:=True
  5144.   else version1_01_16:=False;
  5145.  { if Options.CheckBox1.Checked=True then LagTimeParlour:=True
  5146.  else LagTimeParlour:=False;
  5147.  if Options.CheckBox2.Checked=True then
  5148.   begin
  5149.   ChopLength:=True;
  5150.   Instant.ComboBox1Change(Instant);
  5151.   end
  5152.  else
  5153.   begin
  5154.   ChopLength:=False;
  5155.   Instant.ComboBox1Change(Instant);
  5156.   end;
  5157.  for FeedNo:=0 to rFeedInfo.iNoFeeds-1 do
  5158.   begin
  5159.   if rFeedInfo.ACHOintoWSCsNDF then
  5160.    rFeedInfo.TMRFeed[FeedNo].C1:=rFeedInfo.TMRFeed[FeedNo].ACHO
  5161.                   -rFeedInfo.TMRFeed[FeedNo].QuickStarch-rFeedInfo.TMRFeed[FeedNo].C1sNDF//WSC
  5162.   else
  5163.    rFeedInfo.TMRFeed[FeedNo].C1:=rFeedInfo.TMRFeed[FeedNo].ACHO-rFeedInfo.TMRFeed[FeedNo].QuickStarch;//WSC
  5164.   if rFeedInfo.TMRFeed[FeedNo].C1<0 then rFeedInfo.TMRFeed[FeedNo].C1:=0;
  5165.   end;
  5166.   if rFeedInfo.iParlour>0 then
  5167.    for FeedNo:=0 to rFeedInfo.iParlour-1 do
  5168.     begin
  5169.     if rFeedInfo.ACHOintoWSCsNDF then
  5170.      rFeedInfo.ParlourFeed[FeedNo].C1:=rFeedInfo.ParlourFeed[FeedNo].ACHO
  5171.                   -rFeedInfo.ParlourFeed[FeedNo].QuickStarch
  5172.                   -rFeedInfo.ParlourFeed[FeedNo].C1sNDF//WSC
  5173.     else
  5174.      rFeedInfo.ParlourFeed[FeedNo].C1:=rFeedInfo.ParlourFeed[FeedNo].ACHO
  5175.                   -rFeedInfo.ParlourFeed[FeedNo].QuickStarch;//WSC
  5176.     if rFeedInfo.ParlourFeed[FeedNo].C1<0 then rFeedInfo.ParlourFeed[FeedNo].C1:=0;
  5177.     end;
  5178.   if rFeedInfo.iGrazing>0 then
  5179.   begin
  5180.   if rFeedInfo.ACHOintoWSCsNDF then
  5181.    rFeedInfo.GrazingFeed.C1:=rFeedInfo.GrazingFeed.ACHO
  5182.                   -rFeedInfo.GrazingFeed.QuickStarch-rFeedInfo.GrazingFeed.C1sNDF//WSC
  5183.   else
  5184.    rFeedInfo.GrazingFeed.C1:=rFeedInfo.GrazingFeed.ACHO-rFeedInfo.GrazingFeed.QuickStarch;//WSC
  5185.   if rFeedInfo.GrazingFeed.C1<0 then rFeedInfo.GrazingFeed.C1:=0;
  5186.   end;
  5187.  if Options.CheckBox2.Checked=True then rFeedInfo.DynamicWater:=True
  5188.  else rFeedInfo.DynamicWater:=False;
  5189.  if Options.CheckBox3.Checked=True then rFeedInfo.LagTime:=True
  5190.  else rFeedInfo.LagTime:=False;
  5191.  if Options.CheckBox4.Checked=True then
  5192.   begin
  5193.   rFeedInfo.Long:=True;
  5194.   end
  5195.  else rFeedInfo.Long:=False;
  5196.  if Options.CheckBox5.Checked=True then MicrobesAcidosis:=True
  5197.  else MicrobesAcidosis:=False;
  5198.  if Options.CheckBox6.Checked=True then rFeedInfo.LPBRwithRumination:=True
  5199.  else rFeedInfo.LPBRwithRumination:=False;
  5200.  if Options.Checkbox7.Checked=True then rFeedInfo.Pectins:=True
  5201.  else rFeedInfo.Pectins:=False;   }
  5202.   end;
  5203.  finally
  5204.    Free;
  5205.  end;
  5206. end;
  5207.  
  5208. procedure TMain.ModifyRates1Click(Sender: TObject);
  5209. begin
  5210. if not Assigned(ChangeRates) then
  5211.  TChangeRates.Create(Self);
  5212. ChangeRates.Show;
  5213. end;
  5214.  
  5215.  
  5216. procedure TMain.ReadFileMinerals;
  5217. var
  5218. SupS: TextFile;
  5219. NewLine: String;
  5220. IndexPosn1,m,p: Integer;
  5221. ex: Boolean;
  5222.  
  5223. begin
  5224. ex:=True;
  5225. CopyFile(PWideChar(ExtractFilePath(Paramstr(0))+'Minerals.mrq'),
  5226.          PWideChar(DatabaseDirectory+'min.nsj'),ex);
  5227. AssignFile(SupS,DatabaseDirectory+'min.nsj');
  5228. Reset(SupS);
  5229. while not EOF(SupS) do
  5230.  begin
  5231.  ReadLn(SupS,NewLine);//header
  5232.  ReadLn(Sups,Newline);
  5233.  IndexPosn1:=LastDelimiter(',',NewLine);
  5234.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5235.  for m:=1 to 14 do
  5236.   begin
  5237.   p:=15-m;
  5238.   IndexPosn1:=LastDelimiter(',',NewLine);
  5239.   Minerals.NaReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5240.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5241.   end;
  5242.  ReadLn(SupS,NewLine);//header
  5243.  ReadLn(Sups,Newline);
  5244.  IndexPosn1:=LastDelimiter(',',NewLine);
  5245.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5246.  for m:=1 to 14 do
  5247.   begin
  5248.   p:=15-m;
  5249.   IndexPosn1:=LastDelimiter(',',NewLine);
  5250.   Minerals.KReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5251.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5252.   end;
  5253.  Readln(SupS,NewLine);//header
  5254.  ReadLn(Sups,Newline);
  5255.  IndexPosn1:=LastDelimiter(',',NewLine);
  5256.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5257.  for m:=1 to 14 do
  5258.   begin
  5259.   p:=15-m;
  5260.   IndexPosn1:=LastDelimiter(',',NewLine);
  5261.   Minerals.CaReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5262.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5263.   end;
  5264.  Readln(SupS,NewLine);//header
  5265.  ReadLn(Sups,Newline);
  5266.  IndexPosn1:=LastDelimiter(',',NewLine);
  5267.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5268.  for m:=1 to 14 do
  5269.   begin
  5270.   p:=15-m;
  5271.   IndexPosn1:=LastDelimiter(',',NewLine);
  5272.   Minerals.MgReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5273.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5274.   end;
  5275.  Readln(SupS,NewLine);//header
  5276.  ReadLn(Sups,Newline);
  5277.  IndexPosn1:=LastDelimiter(',',NewLine);
  5278.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5279.  for m:=1 to 14 do
  5280.   begin
  5281.   p:=15-m;
  5282.   IndexPosn1:=LastDelimiter(',',NewLine);
  5283.   Minerals.ClReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5284.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5285.   end;
  5286.  Readln(SupS,NewLine);//header
  5287.  ReadLn(Sups,Newline);
  5288.  IndexPosn1:=LastDelimiter(',',NewLine);
  5289.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5290.  for m:=1 to 14 do
  5291.   begin
  5292.   p:=15-m;
  5293.   IndexPosn1:=LastDelimiter(',',NewLine);
  5294.   Minerals.PReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5295.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5296.   end;
  5297.  Readln(SupS,NewLine);//header
  5298.  ReadLn(Sups,Newline);
  5299.  IndexPosn1:=LastDelimiter(',',NewLine);
  5300.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5301.  for m:=1 to 4 do
  5302.   begin
  5303.   p:=5-m;
  5304.   IndexPosn1:=LastDelimiter(',',NewLine);
  5305.   Minerals.SReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5306.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5307.   end;
  5308.  Readln(SupS,NewLine);//header
  5309.  ReadLn(Sups,Newline);
  5310.  IndexPosn1:=LastDelimiter(',',NewLine);
  5311.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5312.  for m:=1 to 4 do
  5313.   begin
  5314.   p:=5-m;
  5315.   IndexPosn1:=LastDelimiter(',',NewLine);
  5316.   Minerals.CuReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5317.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5318.   end;
  5319.  Readln(SupS,NewLine);//header
  5320.  ReadLn(Sups,Newline);
  5321.  IndexPosn1:=LastDelimiter(',',NewLine);
  5322.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5323.  for m:=1 to 4 do
  5324.   begin
  5325.   p:=5-m;
  5326.   IndexPosn1:=LastDelimiter(',',NewLine);
  5327.   Minerals.SeReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5328.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5329.   end;
  5330.  Readln(SupS,NewLine);//header
  5331.  ReadLn(Sups,Newline);
  5332.  IndexPosn1:=LastDelimiter(',',NewLine);
  5333.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5334.  for m:=1 to 4 do
  5335.   begin
  5336.   p:=5-m;
  5337.   IndexPosn1:=LastDelimiter(',',NewLine);
  5338.   Minerals.ZnReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5339.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5340.   end;
  5341.  Readln(SupS,NewLine);//header
  5342.  ReadLn(Sups,Newline);
  5343.  IndexPosn1:=LastDelimiter(',',NewLine);
  5344.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5345.  for m:=1 to 4 do
  5346.   begin
  5347.   p:=5-m;
  5348.   IndexPosn1:=LastDelimiter(',',NewLine);
  5349.   Minerals.MnReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5350.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5351.   end;
  5352.  Readln(SupS,NewLine);//header
  5353.  ReadLn(Sups,Newline);
  5354.  IndexPosn1:=LastDelimiter(',',NewLine);
  5355.  Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5356.  for m:=1 to 4 do
  5357.   begin
  5358.   p:=5-m;
  5359.   IndexPosn1:=LastDelimiter(',',NewLine);
  5360.   Minerals.MoReq[p]:=StrToFloat(Copy(NewLine,IndexPosn1+1,Length(NewLine)-IndexPosn1));
  5361.   Delete(NewLine,IndexPosn1,Length(NewLine)-IndexPosn1+1);
  5362.   end;
  5363. end;
  5364. CloseFile(SupS);
  5365. DeleteFile(DatabaseDirectory+'min.nsj');
  5366. end;
  5367.  
  5368. function TMain.HH(Command: Word; Data: Integer;
  5369.   var CallHelp: Boolean): Boolean;
  5370. begin
  5371.   if (Command = 0) and (Data = 0) then
  5372.       HtmlHelp(Application.Handle,
  5373.         PWideChar(Application.HelpFile),
  5374.         HH_DISPLAY_TOC, 0);
  5375. {if (Command = 1) then
  5376.     HtmlHelp(Application.Handle,
  5377.       PChar(Format('%s::/H%5.5d.htm',
  5378.         [Application.HelpFile, Data])),
  5379.       HH_DISPLAY_TOPIC, 0);}
  5380.   CallHelp := False;
  5381. end;
  5382.  
  5383. procedure TMain.ForagesfromDatabase1Click(Sender: TObject);
  5384. var
  5385. crDefault: TCursor;
  5386. m,n,TempDBNotConnected: Integer;
  5387. OldCombo: String;
  5388.  
  5389. begin
  5390. crDefault:=Screen.Cursor;
  5391. Screen.Cursor:=crHourGlass;
  5392. if FDConnection1.Ping then
  5393.  begin
  5394.  UpdateYesNo:=True;
  5395.  
  5396.  if FileExists(DatabaseDirectory+'\OldDBClientFeeds.ph6') then
  5397.   DeleteFile(DatabaseDirectory+'\OldDBClientFeeds.ph6');
  5398.  CopyFile(PWideChar(DatabaseDirectory+'\DBClientFeeds.ph6'),PWideChar(DatabaseDirectory+'\OldDBClientFeeds.ph6'),False);
  5399.  try
  5400.   begin
  5401.   FDConnection1.Connected:=True;
  5402.  
  5403.   if DBNotConnected=1 then
  5404.    begin
  5405.    AreAmendClient;
  5406.    FDTable1.TableName:=' Client ';
  5407.    FDTable1.Open;
  5408.    for n := 0 to Length(AmendClient)-1 do
  5409.     begin
  5410.     if AmendClient[n].New=-1 then //delete
  5411.      begin
  5412.      if FDTable1.Locate('Consultant;ID',VarArrayOf([Consultant,AmendClient[n].ID]),[]) then
  5413.       begin
  5414.       FDTable1.Delete;
  5415.       end;
  5416.      end
  5417.     else if AmendClient[n].New=1 then //insert
  5418.      begin
  5419.      for m := 0 to Length(DBClientFeeds)-1 do
  5420.       if AmendClient[n].ID=DBClientFeeds[m].ID then
  5421.        begin
  5422.        InsertClient(DBClientFeeds[m],1);
  5423.        DBClientFeeds[m].New:=0;
  5424.        end;
  5425.      end
  5426.     else if AmendClient[n].New=-2 then //append new cost or new DM
  5427.      begin
  5428.      for m := 0 to Length(DBClientFeeds)-1 do
  5429.       if AmendClient[n].ID=DBClientFeeds[m].ID then
  5430.        begin
  5431.        InsertClient(DBClientFeeds[m],-2);
  5432.        DBClientFeeds[m].New:=0;
  5433.        AmendClient[n].New:=0;
  5434.        end;
  5435.      end;
  5436.     end;
  5437.    FDTable1.Close;
  5438.    end;
  5439.   end;
  5440.  except
  5441.   begin
  5442.   if FileExists(DatabaseDirectory+'\DBClientFeeds.ph6') then
  5443.    DeleteFile(DatabaseDirectory+'\DBClientFeeds.ph6');
  5444.   CopyFile(PWideChar(DatabaseDirectory+'\OldDBClientFeeds.ph6'),PWideChar(DatabaseDirectory+'\DBClientFeeds.ph6'),False);
  5445.   end;
  5446.  end;
  5447.  TempDBNotConnected:=DBNotConnected;
  5448.  DBNotConnected:=0;
  5449.  SetUpDBClientFeeds;
  5450.  DBNotConnected:=TempDBNotConnected;
  5451.  UpdateYesNo:=False;
  5452.  FDConnection1.Connected:=False;
  5453. // Instant.LoadMainData;
  5454.  FeedingStrategy.LoadLiquidFeeds;
  5455.  if Instant.ComboBox5.Text=Welcome.ComboBox1.Text then
  5456.   begin
  5457.   OldCombo:=Instant.ComboBox1.Text;
  5458.   Instant.ComboBoxFill(Instant.ComboBox1,Instant.ComboBox5);
  5459.   Instant.ComboBox1.Text:=OldCombo;
  5460.   end;
  5461.  if Instant.ComboBox6.Text=Welcome.ComboBox1.Text then
  5462.   begin
  5463.   OldCombo:=Instant.ComboBox2.Text;
  5464.   Instant.ComboBoxFill(Instant.ComboBox2,Instant.ComboBox6);
  5465.   Instant.ComboBox2.Text:=OldCombo;
  5466.   end;
  5467.  if Instant.ComboBox7.Text=Welcome.ComboBox1.Text then
  5468.   begin
  5469.   OldCombo:=Instant.ComboBox3.Text;
  5470.   Instant.ComboBoxFill(Instant.ComboBox3,Instant.ComboBox7);
  5471.   Instant.ComboBox3.Text:=OldCombo;
  5472.   end;
  5473.  if Instant.ComboBox8.Text=Welcome.ComboBox1.Text then
  5474.   begin
  5475.   OldCombo:=Instant.ComboBox4.Text;
  5476.   Instant.ComboBoxFill(Instant.ComboBox4,Instant.ComboBox8);
  5477.   Instant.ComboBox4.Text:=OldCombo;
  5478.   end;
  5479.  if Instant.ComboBox9.Text=Welcome.ComboBox1.Text then
  5480.   begin
  5481.   OldCombo:=Instant.ComboBox10.Text;
  5482.   Instant.ComboBoxFill(Instant.ComboBox10,Instant.ComboBox9);
  5483.   Instant.ComboBox10.Text:=OldCombo;
  5484.   end;
  5485.  if Instant.ComboBox11.Text=Welcome.ComboBox1.Text then
  5486.   begin
  5487.   OldCombo:=Instant.ComboBox12.Text;
  5488.   Instant.ComboBoxFill(Instant.ComboBox12,Instant.ComboBox11);
  5489.   Instant.ComboBox12.Text:=OldCombo;
  5490.   end;
  5491.  if Instant.ComboBox13.Text=Welcome.ComboBox1.Text then
  5492.   begin
  5493.   OldCombo:=Instant.ComboBox14.Text;
  5494.   Instant.ComboBoxFill(Instant.ComboBox14,Instant.ComboBox13);
  5495.   Instant.ComboBox14.Text:=OldCombo;
  5496.   end;
  5497.  if Instant.ComboBox15.Text=Welcome.ComboBox1.Text then
  5498.   begin
  5499.   OldCombo:=Instant.ComboBox16.Text;
  5500.   Instant.ComboBoxFill(Instant.ComboBox16,Instant.ComboBox15);
  5501.   Instant.ComboBox16.Text:=OldCombo;
  5502.   end;
  5503.  if Instant.ComboBox17.Text=Welcome.ComboBox1.Text then
  5504.   begin
  5505.   OldCombo:=Instant.ComboBox18.Text;
  5506.   Instant.ComboBoxFill(Instant.ComboBox18,Instant.ComboBox17);
  5507.   Instant.ComboBox18.Text:=OldCombo;
  5508.   end;
  5509.  if Instant.ComboBox19.Text=Welcome.ComboBox1.Text then
  5510.   begin
  5511.   OldCombo:=Instant.ComboBox20.Text;
  5512.   Instant.ComboBoxFill(Instant.ComboBox20,Instant.ComboBox19);
  5513.   Instant.ComboBox20.Text:=OldCombo;
  5514.   end;
  5515.  if Instant.ComboBox21.Text=Welcome.ComboBox1.Text then
  5516.   begin
  5517.   OldCombo:=Instant.ComboBox22.Text;
  5518.   Instant.ComboBoxFill(Instant.ComboBox22,Instant.ComboBox21);
  5519.   Instant.ComboBox22.Text:=OldCombo;
  5520.   end;
  5521.  if Instant.ComboBox23.Text=Welcome.ComboBox1.Text then
  5522.   begin
  5523.   OldCombo:=Instant.ComboBox24.Text;
  5524.   Instant.ComboBoxFill(Instant.ComboBox24,Instant.ComboBox23);
  5525.   Instant.ComboBox24.Text:=OldCombo;
  5526.   end;
  5527.  if Instant.ComboBox25.Text=Welcome.ComboBox1.Text then
  5528.   begin
  5529.   OldCombo:=Instant.ComboBox26.Text;
  5530.   Instant.ComboBoxFill(Instant.ComboBox26,Instant.ComboBox25);
  5531.   Instant.ComboBox26.Text:=OldCombo;
  5532.   end;
  5533.  if Instant.ComboBox27.Text=Welcome.ComboBox1.Text then
  5534.   begin
  5535.   OldCombo:=Instant.ComboBox28.Text;
  5536.   Instant.ComboBoxFill(Instant.ComboBox28,Instant.ComboBox27);
  5537.   Instant.ComboBox28.Text:=OldCombo;
  5538.   end;
  5539.  if Instant.ComboBox29.Text=Welcome.ComboBox1.Text then
  5540.   begin
  5541.   OldCombo:=Instant.ComboBox30.Text;
  5542.   Instant.ComboBoxFill(Instant.ComboBox30,Instant.ComboBox29);
  5543.   Instant.ComboBox30.Text:=OldCombo;
  5544.   end;
  5545.  if Instant.ComboBox31.Text=Welcome.ComboBox1.Text then
  5546.   begin
  5547.   OldCombo:=Instant.ComboBox32.Text;
  5548.   Instant.ComboBoxFill(Instant.ComboBox32,Instant.ComboBox31);
  5549.   Instant.ComboBox32.Text:=OldCombo;
  5550.   end;
  5551.  end
  5552. else
  5553.  begin
  5554.  ShowMessage('No internet connection!');
  5555.  end;
  5556. Screen.Cursor:=crDefault;
  5557. end;
  5558.  
  5559. procedure TMain.FormClose(Sender: TObject; var Action: TCloseAction);
  5560. begin
  5561. SpeedButton3Click(Main);
  5562. end;
  5563.  
  5564. procedure TMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  5565. begin
  5566. HtmlHelp(0, nil, HH_CLOSE_ALL, 0);
  5567. end;
  5568.  
  5569. procedure TMain.PreMixes1Click(Sender: TObject);
  5570. begin
  5571. if not Assigned(BlendPage) then
  5572.  Application.CreateForm(TBlendPage, BlendPage);
  5573. BlendPage.Show;
  5574. end;
  5575.  
  5576. procedure TMain.About1Click(Sender: TObject);
  5577. begin
  5578. if AboutForm.ShowModal=mrOK then
  5579. ;
  5580. end;
  5581.  
  5582. procedure TMain.SpeedButton11Click(Sender: TObject);
  5583. begin
  5584. Welcome.Show;
  5585. end;
  5586.  
  5587. procedure TMain.ShowAddFeedIngredients1Click(Sender: TObject);
  5588. begin
  5589. if not Assigned(FeedsAdded) then
  5590.  Application.CreateForm(TFeedsAdded, FeedsAdded);
  5591. FeedsAdded.Show;
  5592. end;
  5593.  
  5594. procedure TMain.ShowDiet1Click(Sender: TObject);
  5595. begin
  5596. if EnlargeDiet then
  5597.  begin
  5598.  EnlargeDiet:=False;
  5599.  ShowDiet1.Checked:=False;
  5600.  EnlargeOutput:=False;
  5601.  Enlarge1.Checked:=False;
  5602.  end
  5603. else
  5604.  begin
  5605.  EnlargeOutput:=True;
  5606.  Enlarge1.Checked:=True;
  5607.  EnlargeGraphs:=False;
  5608.  ShowGraphs1.Checked:=False;
  5609.  EnlargeDiet:=True;
  5610.  EnlargeMilk:=False;
  5611.  ShowMilk1.Checked:=False;
  5612.  EnlargeNutrients:=False;
  5613.  ShowNutrients1.Checked:=False;
  5614.  EnlargeRumen:=False;
  5615.  ShowRumenFunctions1.Checked:=False;
  5616.  EnlargeMinerals:=False;
  5617.  ShowMinerals1.Checked:=False;
  5618.  end;
  5619. end;
  5620.  
  5621.  
  5622. procedure TMain.ShowGraphs1Click(Sender: TObject);
  5623. begin
  5624. if EnlargeGraphs then
  5625.  begin
  5626.  EnlargeGraphs:=False;
  5627.  ShowGraphs1.Checked:=False;
  5628.  EnlargeOutput:=False;
  5629.  Enlarge1.Checked:=False;
  5630.  end
  5631. else
  5632.  begin
  5633.  EnlargeOutput:=True;
  5634.  Enlarge1.Checked:=True;
  5635.  EnlargeGraphs:=True;
  5636.  EnlargeDiet:=False;
  5637.  ShowDiet1.Checked:=False;
  5638.  EnlargeMilk:=False;
  5639.  ShowMilk1.Checked:=False;
  5640.  EnlargeNutrients:=False;
  5641.  ShowNutrients1.Checked:=False;
  5642.  EnlargeRumen:=False;
  5643.  ShowRumenFunctions1.Checked:=False;
  5644.  EnlargeMinerals:=False;
  5645.  ShowMinerals1.Checked:=False;
  5646.  end;
  5647. end;
  5648.  
  5649. procedure TMain.ShowMilk1Click(Sender: TObject);
  5650. begin
  5651. if EnlargeMilk then
  5652.  begin
  5653.  EnlargeMilk:=False;
  5654.  ShowMilk1.Checked:=False;
  5655.  EnlargeOutput:=False;
  5656.  Enlarge1.Checked:=False;
  5657.  end
  5658. else
  5659.  begin
  5660.  EnlargeOutput:=True;
  5661.  Enlarge1.Checked:=True;
  5662.  EnlargeGraphs:=False;
  5663.  ShowGraphs1.Checked:=False;
  5664.  EnlargeDiet:=False;
  5665.  ShowDiet1.Checked:=False;
  5666.  EnlargeMilk:=True;
  5667.  EnlargeNutrients:=False;
  5668.  ShowNutrients1.Checked:=False;
  5669.  EnlargeRumen:=False;
  5670.  ShowRumenFunctions1.Checked:=False;
  5671.  EnlargeMinerals:=False;
  5672.  ShowMinerals1.Checked:=False;
  5673.  end;
  5674. end;
  5675.  
  5676. procedure TMain.ShowMinerals1Click(Sender: TObject);
  5677. begin
  5678. if EnlargeMinerals then
  5679.  begin
  5680.  EnlargeMinerals:=False;
  5681.  ShowMinerals1.Checked:=False;
  5682.  EnlargeOutput:=False;
  5683.  Enlarge1.Checked:=False;
  5684.  end
  5685. else
  5686.  begin
  5687.  EnlargeOutput:=True;
  5688.  Enlarge1.Checked:=True;
  5689.  EnlargeGraphs:=False;
  5690.  ShowGraphs1.Checked:=False;
  5691.  EnlargeDiet:=False;
  5692.  ShowDiet1.Checked:=False;
  5693.  EnlargeMilk:=False;
  5694.  ShowMilk1.Checked:=False;
  5695.  EnlargeNutrients:=False;
  5696.  ShowNutrients1.Checked:=False;
  5697.  EnlargeRumen:=False;
  5698.  ShowRumenFunctions1.Checked:=False;
  5699.  EnlargeMinerals:=True;
  5700.  end;
  5701. end;
  5702.  
  5703. procedure TMain.ShowNutrients1Click(Sender: TObject);
  5704. begin
  5705. if EnlargeNutrients then
  5706.  begin
  5707.  EnlargeNutrients:=False;
  5708.  ShowNutrients1.Checked:=False;
  5709.  EnlargeOutput:=False;
  5710.  Enlarge1.Checked:=False;
  5711.  end
  5712. else
  5713.  begin
  5714.  EnlargeOutput:=True;
  5715.  Enlarge1.Checked:=True;
  5716.  EnlargeGraphs:=False;
  5717.  ShowGraphs1.Checked:=False;
  5718.  EnlargeDiet:=False;
  5719.  ShowDiet1.Checked:=False;
  5720.  EnlargeMilk:=False;
  5721.  ShowMilk1.Checked:=False;
  5722.  EnlargeNutrients:=True;
  5723.  EnlargeRumen:=False;
  5724.  ShowRumenFunctions1.Checked:=False;
  5725.  EnlargeMinerals:=False;
  5726.  ShowMinerals1.Checked:=False;
  5727.  end;
  5728. end;
  5729.  
  5730. procedure TMain.ShowRumenFunctions1Click(Sender: TObject);
  5731. begin
  5732. if EnlargeRumen then
  5733.  begin
  5734.  EnlargeRumen:=False;
  5735.  ShowRumenFunctions1.Checked:=False;
  5736.  EnlargeOutput:=False;
  5737.  Enlarge1.Checked:=False;
  5738.  end
  5739. else
  5740.  begin
  5741.  EnlargeOutput:=True;
  5742.  Enlarge1.Checked:=True;
  5743.  EnlargeGraphs:=False;
  5744.  ShowGraphs1.Checked:=False;
  5745.  EnlargeDiet:=False;
  5746.  ShowDiet1.Checked:=False;
  5747.  EnlargeMilk:=False;
  5748.  ShowMilk1.Checked:=False;
  5749.  EnlargeNutrients:=False;
  5750.  ShowNutrients1.Checked:=False;
  5751.  EnlargeRumen:=True;
  5752.  EnlargeMinerals:=False;
  5753.  ShowMinerals1.Checked:=False;
  5754.  end;
  5755. end;
  5756.  
  5757. procedure TMain.Analysebcp1Click(Sender: TObject);
  5758. begin
  5759. // BatchMode:=True;
  5760. // Timer1Timer(Main);
  5761. end;
  5762.  
  5763. procedure TMain.AreTheyChecked(var NotChecked: TNonChecked);
  5764. begin
  5765. if Instant.ListCheckBox[1].Checked then
  5766.  begin
  5767.  NotChecked[1]:=0;
  5768.  end
  5769. else if Instant.ComboBox5.Text<>'' then
  5770.  begin
  5771.  NotChecked[1]:=1;
  5772.  end
  5773. else NotChecked[1]:=-1;
  5774. if Instant.ListCheckBox[2].Checked then
  5775.  begin
  5776.  NotChecked[2]:=0;
  5777.  end
  5778. else if Instant.ComboBox6.Text<>'' then
  5779.  begin
  5780.  NotChecked[2]:=2;
  5781.  end
  5782. else NotChecked[2]:=-1;
  5783. if Instant.ListCheckBox[3].Checked then
  5784.  begin
  5785.  NotChecked[3]:=0;
  5786.  end
  5787. else if Instant.ComboBox7.Text<>'' then
  5788.  begin
  5789.  NotChecked[3]:=3;
  5790.  end
  5791. else NotChecked[3]:=-1;
  5792. if Instant.ListCheckBox[4].Checked then
  5793.  begin
  5794.  NotChecked[4]:=0;
  5795.  end
  5796. else if Instant.ComboBox8.Text<>'' then
  5797.  begin
  5798.  NotChecked[4]:=4;
  5799.  end
  5800. else NotChecked[4]:=-1;
  5801. if Instant.ListCheckBox[5].Checked then
  5802.  begin
  5803.  NotChecked[5]:=0;
  5804.  end
  5805. else if Instant.ComboBox9.Text<>'' then
  5806.  begin
  5807.  NotChecked[5]:=5;
  5808.  end
  5809. else NotChecked[5]:=-1;
  5810. if Instant.ListCheckBox[6].Checked then
  5811.  begin
  5812.  NotChecked[6]:=0;
  5813.  end
  5814. else if Instant.ComboBox11.Text<>'' then
  5815.  begin
  5816.  NotChecked[6]:=6;
  5817.  end
  5818. else NotChecked[6]:=-1;
  5819. if Instant.ListCheckBox[7].Checked then
  5820.  begin
  5821.  NotChecked[7]:=0;
  5822.  end
  5823. else if Instant.ComboBox13.Text<>'' then
  5824.  begin
  5825.  NotChecked[7]:=7;
  5826.  end
  5827. else NotChecked[7]:=-1;
  5828. if Instant.ListCheckBox[8].Checked then
  5829.  begin
  5830.  NotChecked[8]:=0;
  5831.  end
  5832. else if Instant.ComboBox15.Text<>'' then
  5833.  begin
  5834.  NotChecked[8]:=8;
  5835.  end
  5836. else NotChecked[8]:=-1;
  5837. if Instant.ListCheckBox[9].Checked then
  5838.  begin
  5839.  NotChecked[9]:=0;
  5840.  end
  5841. else if Instant.ComboBox17.Text<>'' then
  5842.  begin
  5843.  NotChecked[9]:=9;
  5844.  end
  5845. else NotChecked[9]:=-1;
  5846. if Instant.ListCheckBox[10].Checked then
  5847.  begin
  5848.  NotChecked[10]:=0;
  5849.  end
  5850. else if Instant.ComboBox19.Text<>'' then
  5851.  begin
  5852.  NotChecked[10]:=10;
  5853.  end
  5854. else NotChecked[10]:=-1;
  5855. if Instant.ListCheckBox[11].Checked then
  5856.  begin
  5857.  NotChecked[11]:=0;
  5858.  end
  5859. else if Instant.ComboBox21.Text<>'' then
  5860.  begin
  5861.  NotChecked[11]:=11;
  5862.  end
  5863. else NotChecked[11]:=-1;
  5864. if Instant.ListCheckBox[12].Checked then
  5865.  begin
  5866.  NotChecked[12]:=0;
  5867.  end
  5868. else if Instant.ComboBox23.Text<>'' then
  5869.  begin
  5870.  NotChecked[12]:=12;
  5871.  end
  5872. else NotChecked[12]:=-1;
  5873. if Instant.ListCheckBox[13].Checked then
  5874.  begin
  5875.  NotChecked[13]:=0;
  5876.  end
  5877. else if Instant.ComboBox25.Text<>'' then
  5878.  begin
  5879.  NotChecked[13]:=13;
  5880.  end
  5881. else NotChecked[13]:=-1;
  5882. if Instant.ListCheckBox[14].Checked then
  5883.  begin
  5884.  NotChecked[14]:=0;
  5885.  end
  5886. else if Instant.ComboBox27.Text<>'' then
  5887.  begin
  5888.  NotChecked[14]:=14;
  5889.  end
  5890. else NotChecked[14]:=-1;
  5891. if Instant.ListCheckBox[15].Checked then
  5892.  begin
  5893.  NotChecked[15]:=0;
  5894.  end
  5895. else if Instant.ComboBox29.Text<>'' then
  5896.  begin
  5897.  NotChecked[15]:=15;
  5898.  end
  5899. else NotChecked[15]:=-1;
  5900. if Instant.ListCheckBox[16].Checked then
  5901.  begin
  5902.  NotChecked[16]:=0;
  5903.  end
  5904. else if Instant.ComboBox31.Text<>'' then
  5905.  begin
  5906.  NotChecked[16]:=16;
  5907.  end
  5908. else NotChecked[16]:=-1;
  5909. end;
  5910.  
  5911. procedure TMain.SeeWhatChecked(var n,m: Integer);
  5912. begin
  5913. if Instant.ListCheckBox[1].Checked then n:=n+1;
  5914. if Instant.ListCheckBox[2].Checked then n:=n+1;
  5915. if Instant.ListCheckBox[3].Checked then n:=n+1;
  5916. if Instant.ListCheckBox[4].Checked then n:=n+1;
  5917. if Instant.ListCheckBox[5].Checked then n:=n+1;
  5918. if Instant.ListCheckBox[6].Checked then n:=n+1;
  5919. if Instant.ListCheckBox[7].Checked then n:=n+1;
  5920. if Instant.ListCheckBox[8].Checked then n:=n+1;
  5921. if Instant.ListCheckBox[9].Checked then n:=n+1;
  5922. if Instant.ListCheckBox[10].Checked then n:=n+1;
  5923. if Instant.ListCheckBox[11].Checked then n:=n+1;
  5924. if Instant.ListCheckBox[12].Checked then n:=n+1;
  5925. if Instant.ListCheckBox[13].Checked then n:=n+1;
  5926. if Instant.ListCheckBox[14].Checked then n:=n+1;
  5927. if Instant.ListCheckBox[15].Checked then n:=n+1;
  5928. if Instant.ListCheckBox[16].Checked then n:=n+1;
  5929. if (Instant.ListCheckBox[1].Checked) and (Instant.ComboBox5.Text='Pre-Mix') then m:=m+1;
  5930. if (Instant.ListCheckBox[2].Checked) and (Instant.ComboBox6.Text='Pre-Mix') then m:=m+1;
  5931. if (Instant.ListCheckBox[3].Checked) and (Instant.ComboBox7.Text='Pre-Mix') then m:=m+1;
  5932. if (Instant.ListCheckBox[4].Checked) and (Instant.ComboBox8.Text='Pre-Mix') then m:=m+1;
  5933. if (Instant.ListCheckBox[5].Checked) and (Instant.ComboBox9.Text='Pre-Mix') then m:=m+1;
  5934. if (Instant.ListCheckBox[6].Checked) and (Instant.ComboBox11.Text='Pre-Mix') then m:=m+1;
  5935. if (Instant.ListCheckBox[7].Checked) and (Instant.ComboBox13.Text='Pre-Mix') then m:=m+1;
  5936. if (Instant.ListCheckBox[8].Checked) and (Instant.ComboBox15.Text='Pre-Mix') then m:=m+1;
  5937. if (Instant.ListCheckBox[9].Checked) and (Instant.ComboBox17.Text='Pre-Mix') then m:=m+1;
  5938. if (Instant.ListCheckBox[10].Checked) and (Instant.ComboBox19.Text='Pre-Mix') then m:=m+1;
  5939. if (Instant.ListCheckBox[11].Checked) and (Instant.ComboBox21.Text='Pre-Mix') then m:=m+1;
  5940. if (Instant.ListCheckBox[12].Checked) and (Instant.ComboBox23.Text='Pre-Mix') then m:=m+1;
  5941. if (Instant.ListCheckBox[13].Checked) and (Instant.ComboBox25.Text='Pre-Mix') then m:=m+1;
  5942. if (Instant.ListCheckBox[14].Checked) and (Instant.ComboBox27.Text='Pre-Mix') then m:=m+1;
  5943. if (Instant.ListCheckBox[15].Checked) and (Instant.ComboBox29.Text='Pre-Mix') then m:=m+1;
  5944. if (Instant.ListCheckBox[16].Checked) and (Instant.ComboBox31.Text='Pre-Mix') then m:=m+1;
  5945. end;
  5946.  
  5947. procedure TMain.SeeWhatCheckedPreMix(var n: Integer);
  5948. var
  5949. HowManyFeeds,id: Integer;
  5950. WhatPrice: Single;
  5951.  
  5952. begin
  5953. if Instant.ListCheckBox[1].Checked then
  5954.  begin
  5955.  if Instant.ComboBox5.Text='Pre-Mix' then
  5956.   begin
  5957.   Instant.GetPreMixNo(Instant.ComboBox1.Text,HowManyFeeds,WhatPrice,id);
  5958.   n:=n+HowManyFeeds;
  5959.   end
  5960.  else
  5961.   begin
  5962.   n:=n+1;
  5963.   end;
  5964.  end;
  5965. if Instant.ListCheckBox[2].Checked then
  5966.  begin
  5967.  if Instant.ComboBox6.Text='Pre-Mix' then
  5968.   begin
  5969.   Instant.GetPreMixNo(Instant.ComboBox2.Text,HowManyFeeds,WhatPrice,id);
  5970.   n:=n+HowManyFeeds;
  5971.   end
  5972.  else
  5973.   begin
  5974.   n:=n+1;
  5975.   end;
  5976.  end;
  5977. if Instant.ListCheckBox[3].Checked then
  5978.  begin
  5979.  if Instant.ComboBox7.Text='Pre-Mix' then
  5980.   begin
  5981.   Instant.GetPreMixNo(Instant.ComboBox3.Text,HowManyFeeds,WhatPrice,id);
  5982.   n:=n+HowManyFeeds;
  5983.   end
  5984.  else
  5985.   begin
  5986.   n:=n+1;
  5987.   end;
  5988.  end;
  5989. if Instant.ListCheckBox[4].Checked then
  5990.  begin
  5991.  if Instant.ComboBox8.Text='Pre-Mix' then
  5992.   begin
  5993.   Instant.GetPreMixNo(Instant.ComboBox4.Text,HowManyFeeds,WhatPrice,id);
  5994.   n:=n+HowManyFeeds;
  5995.   end
  5996.  else
  5997.   begin
  5998.   n:=n+1;
  5999.   end;
  6000.  end;
  6001. if Instant.ListCheckBox[5].Checked then
  6002.  begin
  6003.  if Instant.ComboBox9.Text='Pre-Mix' then
  6004.   begin
  6005.   Instant.GetPreMixNo(Instant.ComboBox5.Text,HowManyFeeds,WhatPrice,id);
  6006.   n:=n+HowManyFeeds;
  6007.   end
  6008.  else
  6009.   begin
  6010.   n:=n+1;
  6011.   end;
  6012.  end;
  6013. if Instant.ListCheckBox[6].Checked then
  6014.  begin
  6015.  if Instant.ComboBox11.Text='Pre-Mix' then
  6016.   begin
  6017.   Instant.GetPreMixNo(Instant.ComboBox12.Text,HowManyFeeds,WhatPrice,id);
  6018.   n:=n+HowManyFeeds;
  6019.   end
  6020.  else
  6021.   begin
  6022.   n:=n+1;
  6023.   end;
  6024.  end;
  6025. if Instant.ListCheckBox[7].Checked then
  6026.  begin
  6027.  if Instant.ComboBox13.Text='Pre-Mix' then
  6028.   begin
  6029.   Instant.GetPreMixNo(Instant.ComboBox14.Text,HowManyFeeds,WhatPrice,id);
  6030.   n:=n+HowManyFeeds;
  6031.   end
  6032.  else
  6033.   begin
  6034.   n:=n+1;
  6035.   end;
  6036.  end;
  6037. if Instant.ListCheckBox[8].Checked then
  6038.  begin
  6039.  if Instant.ComboBox15.Text='Pre-Mix' then
  6040.   begin
  6041.   Instant.GetPreMixNo(Instant.ComboBox16.Text,HowManyFeeds,WhatPrice,id);
  6042.   n:=n+HowManyFeeds;
  6043.   end
  6044.  else
  6045.   begin
  6046.   n:=n+1;
  6047.   end;
  6048.  end;
  6049. if Instant.ListCheckBox[9].Checked then
  6050.  begin
  6051.  if Instant.ComboBox17.Text='Pre-Mix' then
  6052.   begin
  6053.   Instant.GetPreMixNo(Instant.ComboBox18.Text,HowManyFeeds,WhatPrice,id);
  6054.   n:=n+HowManyFeeds;
  6055.   end
  6056.  else
  6057.   begin
  6058.   n:=n+1;
  6059.   end;
  6060.  end;
  6061. if Instant.ListCheckBox[10].Checked then
  6062.  begin
  6063.  if Instant.ComboBox19.Text='Pre-Mix' then
  6064.   begin
  6065.   Instant.GetPreMixNo(Instant.ComboBox20.Text,HowManyFeeds,WhatPrice,id);
  6066.   n:=n+HowManyFeeds;
  6067.   end
  6068.  else
  6069.   begin
  6070.   n:=n+1;
  6071.   end;
  6072.  end;
  6073. if Instant.ListCheckBox[11].Checked then
  6074.  begin
  6075.  if Instant.ComboBox21.Text='Pre-Mix' then
  6076.   begin
  6077.   Instant.GetPreMixNo(Instant.ComboBox22.Text,HowManyFeeds,WhatPrice,id);
  6078.   n:=n+HowManyFeeds;
  6079.   end
  6080.  else
  6081.   begin
  6082.   n:=n+1;
  6083.   end;
  6084.  end;
  6085. if Instant.ListCheckBox[12].Checked then
  6086.  begin
  6087.  if Instant.ComboBox23.Text='Pre-Mix' then
  6088.   begin
  6089.   Instant.GetPreMixNo(Instant.ComboBox24.Text,HowManyFeeds,WhatPrice,id);
  6090.   n:=n+HowManyFeeds;
  6091.   end
  6092.  else
  6093.   begin
  6094.   n:=n+1;
  6095.   end;
  6096.  end;
  6097. if Instant.ListCheckBox[13].Checked then
  6098.  begin
  6099.  if Instant.ComboBox25.Text='Pre-Mix' then
  6100.   begin
  6101.   Instant.GetPreMixNo(Instant.ComboBox26.Text,HowManyFeeds,WhatPrice,id);
  6102.   n:=n+HowManyFeeds;
  6103.   end
  6104.  else
  6105.   begin
  6106.   n:=n+1;
  6107.   end;
  6108.  end;
  6109. if Instant.ListCheckBox[14].Checked then
  6110.  begin
  6111.  if Instant.ComboBox27.Text='Pre-Mix' then
  6112.   begin
  6113.   Instant.GetPreMixNo(Instant.ComboBox28.Text,HowManyFeeds,WhatPrice,id);
  6114.   n:=n+HowManyFeeds;
  6115.   end
  6116.  else
  6117.   begin
  6118.   n:=n+1;
  6119.   end;
  6120.  end;
  6121. if Instant.ListCheckBox[15].Checked then
  6122.  begin
  6123.  if Instant.ComboBox29.Text='Pre-Mix' then
  6124.   begin
  6125.   Instant.GetPreMixNo(Instant.ComboBox30.Text,HowManyFeeds,WhatPrice,id);
  6126.   n:=n+HowManyFeeds;
  6127.   end
  6128.  else
  6129.   begin
  6130.   n:=n+1;
  6131.   end;
  6132.  end;
  6133. if Instant.ListCheckBox[16].Checked then
  6134.  begin
  6135.  if Instant.ComboBox31.Text='Pre-Mix' then
  6136.   begin
  6137.   Instant.GetPreMixNo(Instant.ComboBox32.Text,HowManyFeeds,WhatPrice,id);
  6138.   n:=n+HowManyFeeds;
  6139.   end
  6140.  else
  6141.   begin
  6142.   n:=n+1;
  6143.   end;
  6144.  end;
  6145. end;
  6146.  
  6147. procedure TMain.AddForage1Click(Sender: TObject);
  6148. begin
  6149. if not Assigned(ConvertTopH6plus) then
  6150.  Application.CreateForm(TConvertTopH6plus, ConvertTopH6plus);
  6151. //try
  6152. if DBConnected then
  6153.  ConvertTopH6plus.ShowModal
  6154. else
  6155.  ShowMessage('No internet connection!');
  6156.  
  6157.  //finally
  6158. // ConvertTopH6plus.Free;
  6159. //end;
  6160. end;
  6161.  
  6162. procedure TMain.AddPreMix(n,ID: Integer;PreM: TCategory;Total: Single);
  6163. var
  6164. TPrice: Single;
  6165.  
  6166. begin
  6167.   if LangID=1 then DBPreMixes[n].Name:=SetNameP.Edit1.Text
  6168.   else if LangID=2 then DBPreMixes[n].Name:=SetNameP.Edit1.Text
  6169.   else if LangID=3 then DBPreMixes[n].Name:=SetNameP.Edit1.Text
  6170.   else if LangID=4 then DBPreMixes[n].Name:=SetNameP.Edit1.Text;
  6171.   DBPreMixes[n].TypeF:='Pre-Mix';
  6172.  //Put data into premix
  6173.  
  6174.   DBPreMixes[n].FC_1:=PreM.Category[1];
  6175.   DBPreMixes[n].FN_1:=PreM.FName[1];
  6176.   DBPreMixes[n].FA_1:=PreM.FAmount[1]/Total*100;
  6177.   NewPreMix[0].FC_1:=PreM.Category[1];
  6178.   NewPreMix[0].FN_1:=PreM.FName[1];
  6179.   NewPreMix[0].FA_1:=PreM.FAmount[1]/Total*100;
  6180.   DBPreMixes[n].FC_2:=PreM.Category[2];
  6181.   DBPreMixes[n].FN_2:=PreM.FName[2];
  6182.   DBPreMixes[n].FA_2:=PreM.FAmount[2]/Total*100;
  6183.   NewPreMix[0].FC_2:=PreM.Category[2];
  6184.   NewPreMix[0].FN_2:=PreM.FName[2];
  6185.   NewPreMix[0].FA_2:=PreM.FAmount[2]/Total*100;
  6186.   DBPreMixes[n].FC_3:=PreM.Category[3];
  6187.   DBPreMixes[n].FN_3:=PreM.FName[3];
  6188.   DBPreMixes[n].FA_3:=PreM.FAmount[3]/Total*100;
  6189.   NewPreMix[0].FC_3:=PreM.Category[3];
  6190.   NewPreMix[0].FN_3:=PreM.FName[3];
  6191.   NewPreMix[0].FA_3:=PreM.FAmount[3]/Total*100;
  6192.   DBPreMixes[n].FC_4:=PreM.Category[4];
  6193.   DBPreMixes[n].FN_4:=PreM.FName[4];
  6194.   DBPreMixes[n].FA_4:=PreM.FAmount[4]/Total*100;
  6195.   NewPreMix[0].FC_4:=PreM.Category[4];
  6196.   NewPreMix[0].FN_4:=PreM.FName[4];
  6197.   NewPreMix[0].FA_4:=PreM.FAmount[4]/Total*100;
  6198.   DBPreMixes[n].FC_5:=PreM.Category[5];
  6199.   DBPreMixes[n].FN_5:=PreM.FName[5];
  6200.   DBPreMixes[n].FA_5:=PreM.FAmount[5]/Total*100;
  6201.   NewPreMix[0].FC_5:=PreM.Category[5];
  6202.   NewPreMix[0].FN_5:=PreM.FName[5];
  6203.   NewPreMix[0].FA_5:=PreM.FAmount[5]/Total*100;
  6204.   DBPreMixes[n].FC_6:=PreM.Category[6];
  6205.   DBPreMixes[n].FN_6:=PreM.FName[6];
  6206.   DBPreMixes[n].FA_6:=PreM.FAmount[6]/Total*100;
  6207.   NewPreMix[0].FC_6:=PreM.Category[6];
  6208.   NewPreMix[0].FN_6:=PreM.FName[6];
  6209.   NewPreMix[0].FA_6:=PreM.FAmount[6]/Total*100;
  6210.   DBPreMixes[n].FC_7:=PreM.Category[7];
  6211.   DBPreMixes[n].FN_7:=PreM.FName[7];
  6212.   DBPreMixes[n].FA_7:=PreM.FAmount[7]/Total*100;
  6213.   NewPreMix[0].FC_7:=PreM.Category[7];
  6214.   NewPreMix[0].FN_7:=PreM.FName[7];
  6215.   NewPreMix[0].FA_7:=PreM.FAmount[7]/Total*100;
  6216.   DBPreMixes[n].FC_8:=PreM.Category[8];
  6217.   DBPreMixes[n].FN_8:=PreM.FName[8];
  6218.   DBPreMixes[n].FA_8:=PreM.FAmount[8]/Total*100;
  6219.   NewPreMix[0].FC_8:=PreM.Category[8];
  6220.   NewPreMix[0].FN_8:=PreM.FName[8];
  6221.   NewPreMix[0].FA_8:=PreM.FAmount[8]/Total*100;
  6222.   DBPreMixes[n].FC_9:=PreM.Category[9];
  6223.   DBPreMixes[n].FN_9:=PreM.FName[9];
  6224.   DBPreMixes[n].FA_9:=PreM.FAmount[9]/Total*100;
  6225.   NewPreMix[0].FC_9:=PreM.Category[9];
  6226.   NewPreMix[0].FN_9:=PreM.FName[9];
  6227.   NewPreMix[0].FA_9:=PreM.FAmount[9]/Total*100;
  6228.   DBPreMixes[n].FC_10:=PreM.Category[10];
  6229.   DBPreMixes[n].FN_10:=PreM.FName[10];
  6230.   DBPreMixes[n].FA_10:=PreM.FAmount[10]/Total*100;
  6231.   NewPreMix[0].FC_10:=PreM.Category[10];
  6232.   NewPreMix[0].FN_10:=PreM.FName[10];
  6233.   NewPreMix[0].FA_10:=PreM.FAmount[10]/Total*100;
  6234.   DBPreMixes[n].FC_11:=PreM.Category[11];
  6235.   DBPreMixes[n].FN_11:=PreM.FName[11];
  6236.   DBPreMixes[n].FA_11:=PreM.FAmount[11]/Total*100;
  6237.   NewPreMix[0].FC_11:=PreM.Category[11];
  6238.   NewPreMix[0].FN_11:=PreM.FName[11];
  6239.   NewPreMix[0].FA_11:=PreM.FAmount[11]/Total*100;
  6240.   DBPreMixes[n].FC_12:=PreM.Category[12];
  6241.   DBPreMixes[n].FN_12:=PreM.FName[12];
  6242.   DBPreMixes[n].FA_12:=PreM.FAmount[12]/Total*100;
  6243.   NewPreMix[0].FC_12:=PreM.Category[12];
  6244.   NewPreMix[0].FN_12:=PreM.FName[12];
  6245.   NewPreMix[0].FA_12:=PreM.FAmount[12]/Total*100;
  6246.   DBPreMixes[n].FC_13:=PreM.Category[13];
  6247.   DBPreMixes[n].FN_13:=PreM.FName[13];
  6248.   DBPreMixes[n].FA_13:=PreM.FAmount[13]/Total*100;
  6249.   NewPreMix[0].FC_13:=PreM.Category[13];
  6250.   NewPreMix[0].FN_13:=PreM.FName[13];
  6251.   NewPreMix[0].FA_13:=PreM.FAmount[13]/Total*100;
  6252.   DBPreMixes[n].FC_14:=PreM.Category[14];
  6253.   DBPreMixes[n].FN_14:=PreM.FName[14];
  6254.   DBPreMixes[n].FA_14:=PreM.FAmount[14]/Total*100;
  6255.   NewPreMix[0].FC_14:=PreM.Category[14];
  6256.   NewPreMix[0].FN_14:=PreM.FName[14];
  6257.   NewPreMix[0].FA_14:=PreM.FAmount[14]/Total*100;
  6258.   DBPreMixes[n].FC_15:=PreM.Category[15];
  6259.   DBPreMixes[n].FN_15:=PreM.FName[15];
  6260.   DBPreMixes[n].FA_15:=PreM.FAmount[15]/Total*100;
  6261.   NewPreMix[0].FC_15:=PreM.Category[15];
  6262.   NewPreMix[0].FN_15:=PreM.FName[15];
  6263.   NewPreMix[0].FA_15:=PreM.FAmount[15]/Total*100;
  6264.   DBPreMixes[n].FC_16:=PreM.Category[16];
  6265.   DBPreMixes[n].FN_16:=PreM.FName[16];
  6266.   DBPreMixes[n].FA_16:=PreM.FAmount[16]/Total*100;
  6267.   NewPreMix[0].FC_16:=PreM.Category[16];
  6268.   NewPreMix[0].FN_16:=PreM.FName[16];
  6269.   NewPreMix[0].FA_16:=PreM.FAmount[16]/Total*100;
  6270.   DBPreMixes[n].FC_17:=PreM.Category[17];
  6271.   DBPreMixes[n].FN_17:=PreM.FName[17];
  6272.   DBPreMixes[n].FA_17:=PreM.FAmount[17]/Total*100;
  6273.   NewPreMix[0].FC_17:=PreM.Category[17];
  6274.   NewPreMix[0].FN_17:=PreM.FName[17];
  6275.   NewPreMix[0].FA_17:=PreM.FAmount[17]/Total*100;
  6276.   DBPreMixes[n].FC_18:=PreM.Category[18];
  6277.   DBPreMixes[n].FN_18:=PreM.FName[18];
  6278.   DBPreMixes[n].FA_18:=PreM.FAmount[18]/Total*100;
  6279.   NewPreMix[0].FC_18:=PreM.Category[18];
  6280.   NewPreMix[0].FN_18:=PreM.FName[18];
  6281.   NewPreMix[0].FA_18:=PreM.FAmount[18]/Total*100;
  6282.   TPrice:=0;
  6283.   for n := 1 to 18 do
  6284.    TPrice:=TPrice+PreM.FPrice[n]/Total;
  6285.   DBPreMixes[n].Cost:=TPrice;
  6286.   NewPreMix[0].Cost:=TPrice;
  6287.   DBPreMixes[n].New:=1;
  6288.   DBPreMixes[n].ID:=ID;
  6289. end;
  6290.  
  6291. procedure TMain.AdjustfNDF1Click(Sender: TObject);
  6292. begin
  6293. if not Assigned(AdjustfNDF) then
  6294.  Application.CreateForm(TAdjustfNDF, AdjustfNDF);
  6295. if AdjustfNDF.ShowModal=mrOK then
  6296.  begin
  6297.  DBClientFeeds[AdjustfNDFClientFeed].New:=-3;
  6298.  DBClientFeeds[AdjustfNDFClientFeed].GasA:=((1-(AdjustfNDF.ScrollBar1.Position-45)/(85-45))*(85-45)+45)/fNDFasProp;  //AdjustfNDF.ScrollBar1.Position
  6299.  if Instant.ComboBox1.Text<>'' then Instant.ComboBox1Change(Self);
  6300.  end;
  6301.  
  6302. end;
  6303.  
  6304. procedure TMain.Admin1Click(Sender: TObject);
  6305. begin
  6306. if not Assigned(Admin) then
  6307.  Application.CreateForm(TAdmin, Admin);
  6308. Administrator:=True;
  6309. Admin.Show;
  6310. end;
  6311.  
  6312. procedure TMain.AutoCreatePreMix1Click(Sender: TObject);
  6313. {var
  6314. n,m,HowManyFeeds,id,I,HighID: Integer;
  6315. TotalAmount,TPrice,WhatPrice,PerCent: Single;
  6316. //Category,FName: array[1..18] of String;
  6317. //FAmount,FPrice: array[1..18] of Single;
  6318. NotChecked: TNonChecked;
  6319. UnCheckedIngredient: array of Integer;
  6320. NameOfTable,FeedName: String;
  6321. AddPre: Boolean;
  6322. NewPMix: TCategory;  }
  6323.  
  6324. begin
  6325. {AutoSolveName:=True;
  6326. n:=0;m:=0;UnCheckedIngredient:=nil;
  6327. for n := 1 to 16 do
  6328.  NotChecked[n]:=0;
  6329. n:=0;
  6330. if AutoCreatePreMix then
  6331.  begin
  6332.  SeeWhatCheckedPreMix(n);
  6333.  end
  6334. else
  6335.  begin
  6336.  SeeWhatChecked(n,m);
  6337.  end;
  6338. if n<2 then
  6339.  begin
  6340.  ShowMessage('Please select at least two ingredients!');
  6341.  end
  6342. else if (m>0) and (not AutoCreatePreMix) then
  6343.  begin
  6344.  ShowMessage('Please do not select a Pre-Mix!');
  6345.  end
  6346. else if n>18 then
  6347.  begin
  6348.  ShowMessage('You have selected more than 18 ingredients! At the moment, that''s not allowed');
  6349.  end
  6350. else
  6351.  begin
  6352. //Set name
  6353.  if SetNameP.ShowModal=mrOK then
  6354.   begin
  6355.   AutoPM:=True;
  6356.   NewPreMix:=nil;
  6357.   SetLength(NewPreMix,1);
  6358.   for n := 1 to 18 do
  6359.    begin
  6360.    NewPMix.Category[n]:='';
  6361.    NewPMix.FName[n]:='';
  6362.    NewPMix.FAmount[n]:=0;
  6363.    NewPMix.FPrice[n]:=0;
  6364.    end;
  6365.   TotalAmount:=0;
  6366.   n:=0;
  6367.   if Instant.ListCheckBox[1].Checked then
  6368.    begin
  6369.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit6.Text);
  6370.    if Instant.ComboBox5.Text='Pre-Mix' then
  6371.     begin
  6372.     Instant.GetPreMixNo(Instant.ComboBox1.Text,HowManyFeeds,WhatPrice,id);
  6373.     for m:=1 to HowManyFeeds do
  6374.      begin
  6375.      n:=n+1;
  6376.      Instant.GetPreMixAmounts(Instant.ComboBox1.Text,NameOfTable,FeedName,PerCent,m);
  6377.      NewPMix.FName[n]:=FeedName+'PRMX';
  6378.      NewPMix.Category[n]:=NameOfTable;
  6379.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit6.Text)*PerCent/100;
  6380.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6381.      end;
  6382.     end
  6383.    else
  6384.     begin
  6385.     n:=n+1;
  6386.     NewPMix.Category[n]:=Instant.ComboBox5.Text;
  6387.     NewPMix.FName[n]:=Instant.ComboBox1.Text;
  6388.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit6.Text);
  6389.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[0].Cost*NewPMix.FAmount[n];
  6390.     end;
  6391.    end;
  6392.   if Instant.ListCheckBox[2].Checked then
  6393.    begin
  6394.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit7.Text);
  6395.    if Instant.ComboBox6.Text='Pre-Mix' then
  6396.     begin
  6397.     Instant.GetPreMixNo(Instant.ComboBox2.Text,HowManyFeeds,WhatPrice,id);
  6398.     for m:=1 to HowManyFeeds do
  6399.      begin
  6400.      n:=n+1;
  6401.      Instant.GetPreMixAmounts(Instant.ComboBox2.Text,NameOfTable,FeedName,PerCent,m);
  6402.      NewPMix.FName[n]:=FeedName+'PRMX';
  6403.      NewPMix.Category[n]:=NameOfTable;
  6404.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit7.Text)*PerCent/100;
  6405.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6406.      end;
  6407.     end
  6408.    else
  6409.     begin
  6410.     n:=n+1;
  6411.     NewPMix.Category[n]:=Instant.ComboBox6.Text;
  6412.     NewPMix.FName[n]:=Instant.ComboBox2.Text;
  6413.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit7.Text);
  6414.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[1].Cost*NewPMix.FAmount[n];
  6415.     end;
  6416.    end;
  6417.   if Instant.ListCheckBox[3].Checked then
  6418.    begin
  6419.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit8.Text);
  6420.    if Instant.ComboBox7.Text='Pre-Mix' then
  6421.     begin
  6422.     Instant.GetPreMixNo(Instant.ComboBox3.Text,HowManyFeeds,WhatPrice,id);
  6423.     for m:=1 to HowManyFeeds do
  6424.      begin
  6425.      n:=n+1;
  6426.      Instant.GetPreMixAmounts(Instant.ComboBox3.Text,NameOfTable,FeedName,PerCent,m);
  6427.      NewPMix.FName[n]:=FeedName+'PRMX';
  6428.      NewPMix.Category[n]:=NameOfTable;
  6429.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit8.Text)*PerCent/100;
  6430.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6431.      end;
  6432.     end
  6433.    else
  6434.     begin
  6435.     n:=n+1;
  6436.     NewPMix.Category[n]:=Instant.ComboBox7.Text;
  6437.     NewPMix.FName[n]:=Instant.ComboBox3.Text;
  6438.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit8.Text);
  6439.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[2].Cost*NewPMix.FAmount[n];
  6440.     end;
  6441.   end;
  6442.   if Instant.ListCheckBox[4].Checked then
  6443.    begin
  6444.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit9.Text);
  6445.    if Instant.ComboBox8.Text='Pre-Mix' then
  6446.     begin
  6447.     Instant.GetPreMixNo(Instant.ComboBox4.Text,HowManyFeeds,WhatPrice,id);
  6448.     for m:=1 to HowManyFeeds do
  6449.      begin
  6450.      n:=n+1;
  6451.      Instant.GetPreMixAmounts(Instant.ComboBox4.Text,NameOfTable,FeedName,PerCent,m);
  6452.      NewPMix.FName[n]:=FeedName+'PRMX';
  6453.      NewPMix.Category[n]:=NameOfTable;
  6454.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit9.Text)*PerCent/100;
  6455.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6456.      end;
  6457.     end
  6458.    else
  6459.     begin
  6460.     n:=n+1;
  6461.     NewPMix.Category[n]:=Instant.ComboBox8.Text;
  6462.     NewPMix.FName[n]:=Instant.ComboBox4.Text;
  6463.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit9.Text);
  6464.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[3].Cost*NewPMix.FAmount[n];
  6465.     end;
  6466.    end;
  6467.   if Instant.ListCheckBox[5].Checked then
  6468.    begin
  6469.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit13.Text);
  6470.    if Instant.ComboBox9.Text='Pre-Mix' then
  6471.     begin
  6472.     Instant.GetPreMixNo(Instant.ComboBox10.Text,HowManyFeeds,WhatPrice,id);
  6473.     for m:=1 to HowManyFeeds do
  6474.      begin
  6475.      n:=n+1;
  6476.      Instant.GetPreMixAmounts(Instant.ComboBox10.Text,NameOfTable,FeedName,PerCent,m);
  6477.      NewPMix.FName[n]:=FeedName+'PRMX';
  6478.      NewPMix.Category[n]:=NameOfTable;
  6479.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit13.Text)*PerCent/100;
  6480.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6481.      end;
  6482.     end
  6483.    else
  6484.     begin
  6485.     n:=n+1;
  6486.     NewPMix.Category[n]:=Instant.ComboBox9.Text;
  6487.     NewPMix.FName[n]:=Instant.ComboBox10.Text;
  6488.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit13.Text);
  6489.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[4].Cost*NewPMix.FAmount[n];
  6490.     end;
  6491.    end;
  6492.   if Instant.ListCheckBox[6].Checked then
  6493.    begin
  6494.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit16.Text);
  6495.    if Instant.ComboBox11.Text='Pre-Mix' then
  6496.     begin
  6497.     Instant.GetPreMixNo(Instant.ComboBox12.Text,HowManyFeeds,WhatPrice,id);
  6498.     for m:=1 to HowManyFeeds do
  6499.      begin
  6500.      n:=n+1;
  6501.      Instant.GetPreMixAmounts(Instant.ComboBox12.Text,NameOfTable,FeedName,PerCent,m);
  6502.      NewPMix.FName[n]:=FeedName+'PRMX';
  6503.      NewPMix.Category[n]:=NameOfTable;
  6504.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit16.Text)*PerCent/100;
  6505.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6506.      end;
  6507.     end
  6508.    else
  6509.     begin
  6510.     n:=n+1;
  6511.     NewPMix.Category[n]:=Instant.ComboBox11.Text;
  6512.     NewPMix.FName[n]:=Instant.ComboBox12.Text;
  6513.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit16.Text);
  6514.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[5].Cost*NewPMix.FAmount[n];
  6515.     end;
  6516.    end;
  6517.   if Instant.ListCheckBox[7].Checked then
  6518.    begin
  6519.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit18.Text);
  6520.    if Instant.ComboBox13.Text='Pre-Mix' then
  6521.     begin
  6522.     Instant.GetPreMixNo(Instant.ComboBox14.Text,HowManyFeeds,WhatPrice,id);
  6523.     for m:=1 to HowManyFeeds do
  6524.      begin
  6525.      n:=n+1;
  6526.      Instant.GetPreMixAmounts(Instant.ComboBox14.Text,NameOfTable,FeedName,PerCent,m);
  6527.      NewPMix.FName[n]:=FeedName+'PRMX';
  6528.      NewPMix.Category[n]:=NameOfTable;
  6529.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit18.Text)*PerCent/100;
  6530.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6531.      end;
  6532.     end
  6533.    else
  6534.     begin
  6535.     n:=n+1;
  6536.     NewPMix.Category[n]:=Instant.ComboBox13.Text;
  6537.     NewPMix.FName[n]:=Instant.ComboBox14.Text;
  6538.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit18.Text);
  6539.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[6].Cost*NewPMix.FAmount[n];
  6540.     end;
  6541.    end;
  6542.   if Instant.ListCheckBox[8].Checked then
  6543.    begin
  6544.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit20.Text);
  6545.    if Instant.ComboBox15.Text='Pre-Mix' then
  6546.     begin
  6547.     Instant.GetPreMixNo(Instant.ComboBox16.Text,HowManyFeeds,WhatPrice,id);
  6548.     for m:=1 to HowManyFeeds do
  6549.      begin
  6550.      n:=n+1;
  6551.      Instant.GetPreMixAmounts(Instant.ComboBox16.Text,NameOfTable,FeedName,PerCent,m);
  6552.      NewPMix.FName[n]:=FeedName+'PRMX';
  6553.      NewPMix.Category[n]:=NameOfTable;
  6554.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit20.Text)*PerCent/100;
  6555.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6556.      end;
  6557.     end
  6558.    else
  6559.     begin
  6560.     n:=n+1;
  6561.     NewPMix.Category[n]:=Instant.ComboBox15.Text;
  6562.     NewPMix.FName[n]:=Instant.ComboBox16.Text;
  6563.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit20.Text);
  6564.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[7].Cost*NewPMix.FAmount[n];
  6565.     end;
  6566.    end;
  6567.   if Instant.ListCheckBox[9].Checked then
  6568.    begin
  6569.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit22.Text);
  6570.    if Instant.ComboBox17.Text='Pre-Mix' then
  6571.     begin
  6572.     Instant.GetPreMixNo(Instant.ComboBox18.Text,HowManyFeeds,WhatPrice,id);
  6573.     for m:=1 to HowManyFeeds do
  6574.      begin
  6575.      n:=n+1;
  6576.      Instant.GetPreMixAmounts(Instant.ComboBox18.Text,NameOfTable,FeedName,PerCent,m);
  6577.      NewPMix.FName[n]:=FeedName+'PRMX';
  6578.      NewPMix.Category[n]:=NameOfTable;
  6579.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit22.Text)*PerCent/100;
  6580.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6581.      end;
  6582.     end
  6583.    else
  6584.     begin
  6585.     n:=n+1;
  6586.     NewPMix.Category[n]:=Instant.ComboBox17.Text;
  6587.     NewPMix.FName[n]:=Instant.ComboBox18.Text;
  6588.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit22.Text);
  6589.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[8].Cost*NewPMix.FAmount[n];
  6590.     end;
  6591.    end;
  6592.   if Instant.ListCheckBox[10].Checked then
  6593.    begin
  6594.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit24.Text);
  6595.    if Instant.ComboBox19.Text='Pre-Mix' then
  6596.     begin
  6597.     Instant.GetPreMixNo(Instant.ComboBox20.Text,HowManyFeeds,WhatPrice,id);
  6598.     for m:=1 to HowManyFeeds do
  6599.      begin
  6600.      n:=n+1;
  6601.      Instant.GetPreMixAmounts(Instant.ComboBox20.Text,NameOfTable,FeedName,PerCent,m);
  6602.      NewPMix.FName[n]:=FeedName+'PRMX';
  6603.      NewPMix.Category[n]:=NameOfTable;
  6604.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit24.Text)*PerCent/100;
  6605.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6606.      end;
  6607.     end
  6608.    else
  6609.     begin
  6610.     n:=n+1;
  6611.     NewPMix.Category[n]:=Instant.ComboBox19.Text;
  6612.     NewPMix.FName[n]:=Instant.ComboBox20.Text;
  6613.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit24.Text);
  6614.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[9].Cost*NewPMix.FAmount[n];
  6615.     end;
  6616.    end;
  6617.   if Instant.ListCheckBox[11].Checked then
  6618.    begin
  6619.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit26.Text);
  6620.    if Instant.ComboBox21.Text='Pre-Mix' then
  6621.     begin
  6622.     Instant.GetPreMixNo(Instant.ComboBox22.Text,HowManyFeeds,WhatPrice,id);
  6623.     for m:=1 to HowManyFeeds do
  6624.      begin
  6625.      n:=n+1;
  6626.      Instant.GetPreMixAmounts(Instant.ComboBox22.Text,NameOfTable,FeedName,PerCent,m);
  6627.      NewPMix.FName[n]:=FeedName+'PRMX';
  6628.      NewPMix.Category[n]:=NameOfTable;
  6629.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit26.Text)*PerCent/100;
  6630.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6631.      end;
  6632.     end
  6633.    else
  6634.     begin
  6635.     n:=n+1;
  6636.     NewPMix.Category[n]:=Instant.ComboBox21.Text;
  6637.     NewPMix.FName[n]:=Instant.ComboBox22.Text;
  6638.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit26.Text);
  6639.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[10].Cost*NewPMix.FAmount[n];
  6640.     end;
  6641.    end;
  6642.   if Instant.ListCheckBox[12].Checked then
  6643.    begin
  6644.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit28.Text);
  6645.    if Instant.ComboBox23.Text='Pre-Mix' then
  6646.     begin
  6647.     Instant.GetPreMixNo(Instant.ComboBox24.Text,HowManyFeeds,WhatPrice,id);
  6648.     for m:=1 to HowManyFeeds do
  6649.      begin
  6650.      n:=n+1;
  6651.      Instant.GetPreMixAmounts(Instant.ComboBox24.Text,NameOfTable,FeedName,PerCent,m);
  6652.      NewPMix.FName[n]:=FeedName+'PRMX';
  6653.      NewPMix.Category[n]:=NameOfTable;
  6654.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit28.Text)*PerCent/100;
  6655.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6656.      end;
  6657.     end
  6658.    else
  6659.     begin
  6660.     n:=n+1;
  6661.     NewPMix.Category[n]:=Instant.ComboBox23.Text;
  6662.     NewPMix.FName[n]:=Instant.ComboBox24.Text;
  6663.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit28.Text);
  6664.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[11].Cost*NewPMix.FAmount[n];
  6665.     end;
  6666.    end;
  6667.   if Instant.ListCheckBox[13].Checked then
  6668.    begin
  6669.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit1.Text);
  6670.    if Instant.ComboBox25.Text='Pre-Mix' then
  6671.     begin
  6672.     Instant.GetPreMixNo(Instant.ComboBox26.Text,HowManyFeeds,WhatPrice,id);
  6673.     for m:=1 to HowManyFeeds do
  6674.      begin
  6675.      n:=n+1;
  6676.      Instant.GetPreMixAmounts(Instant.ComboBox26.Text,NameOfTable,FeedName,PerCent,m);
  6677.      NewPMix.FName[n]:=FeedName+'PRMX';
  6678.      NewPMix.Category[n]:=NameOfTable;
  6679.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit1.Text)*PerCent/100;
  6680.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6681.      end;
  6682.     end
  6683.    else
  6684.     begin
  6685.     n:=n+1;
  6686.     NewPMix.Category[n]:=Instant.ComboBox25.Text;
  6687.     NewPMix.FName[n]:=Instant.ComboBox26.Text;
  6688.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit1.Text);
  6689.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[12].Cost*NewPMix.FAmount[n];
  6690.     end;
  6691.    end;
  6692.   if Instant.ListCheckBox[14].Checked then
  6693.    begin
  6694.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit2.Text);
  6695.    if Instant.ComboBox27.Text='Pre-Mix' then
  6696.     begin
  6697.     Instant.GetPreMixNo(Instant.ComboBox28.Text,HowManyFeeds,WhatPrice,id);
  6698.     for m:=1 to HowManyFeeds do
  6699.      begin
  6700.      n:=n+1;
  6701.      Instant.GetPreMixAmounts(Instant.ComboBox28.Text,NameOfTable,FeedName,PerCent,m);
  6702.      NewPMix.FName[n]:=FeedName+'PRMX';
  6703.      NewPMix.Category[n]:=NameOfTable;
  6704.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit2.Text)*PerCent/100;
  6705.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6706.      end;
  6707.     end
  6708.    else
  6709.     begin
  6710.     n:=n+1;
  6711.     NewPMix.Category[n]:=Instant.ComboBox27.Text;
  6712.     NewPMix.FName[n]:=Instant.ComboBox28.Text;
  6713.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit2.Text);
  6714.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[13].Cost*NewPMix.FAmount[n];
  6715.     end;
  6716.    end;
  6717.   if Instant.ListCheckBox[15].Checked then
  6718.    begin
  6719.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit3.Text);
  6720.    if Instant.ComboBox29.Text='Pre-Mix' then
  6721.     begin
  6722.     Instant.GetPreMixNo(Instant.ComboBox30.Text,HowManyFeeds,WhatPrice,id);
  6723.     for m:=1 to HowManyFeeds do
  6724.      begin
  6725.      n:=n+1;
  6726.      Instant.GetPreMixAmounts(Instant.ComboBox30.Text,NameOfTable,FeedName,PerCent,m);
  6727.      NewPMix.FName[n]:=FeedName+'PRMX';
  6728.      NewPMix.Category[n]:=NameOfTable;
  6729.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit3.Text)*PerCent/100;
  6730.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6731.      end;
  6732.     end
  6733.    else
  6734.     begin
  6735.     n:=n+1;
  6736.     NewPMix.Category[n]:=Instant.ComboBox29.Text;
  6737.     NewPMix.FName[n]:=Instant.ComboBox30.Text;
  6738.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit3.Text);
  6739.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[14].Cost*NewPMix.FAmount[n];
  6740.     end;
  6741.    end;
  6742.   if Instant.ListCheckBox[16].Checked then
  6743.    begin
  6744.    TotalAmount:=TotalAmount+StrToFloat(Instant.Edit4.Text);
  6745.    if Instant.ComboBox31.Text='Pre-Mix' then
  6746.     begin
  6747.     Instant.GetPreMixNo(Instant.ComboBox32.Text,HowManyFeeds,WhatPrice,id);
  6748.     for m:=1 to HowManyFeeds do
  6749.      begin
  6750.      n:=n+1;
  6751.      Instant.GetPreMixAmounts(Instant.ComboBox32.Text,NameOfTable,FeedName,PerCent,m);
  6752.      NewPMix.FName[n]:=FeedName+'PRMX';
  6753.      NewPMix.Category[n]:=NameOfTable;
  6754.      NewPMix.FAmount[n]:=StrToFloat(Instant.Edit4.Text)*PerCent/100;
  6755.      NewPMix.FPrice[n]:=WhatPrice*NewPMix.FAmount[n];
  6756.      end;
  6757.     end
  6758.    else
  6759.     begin
  6760.     n:=n+1;
  6761.     NewPMix.Category[n]:=Instant.ComboBox31.Text;
  6762.     NewPMix.FName[n]:=Instant.ComboBox32.Text;
  6763.     NewPMix.FAmount[n]:=StrToFloat(Instant.Edit4.Text);
  6764.     NewPMix.FPrice[n]:=rFeedInfo.TMRFeed[15].Cost*NewPMix.FAmount[n];
  6765.     end;
  6766.    end;
  6767.  AddPre:=False;
  6768.  if Length(DBPreMixes)>0 then
  6769.   begin
  6770.   for I := 0 to Length(DBPreMixes)-1 do
  6771.    if DBPreMixes[I].Name=SetNameP.Edit1.Text then
  6772.     begin
  6773.     AddPreMix(I,DBPreMixes[I].ID,NewPMix,TotalAmount);
  6774.     AddPre:=True;
  6775.     end;
  6776.   if not AddPre then
  6777.    begin
  6778.    HighID:=0;
  6779.    for I := 0 to Length(DBPreMixes)-1 do
  6780.     begin
  6781.     if DBPreMixes[I].ID>HighID then
  6782.      HighID:=DBPreMixes[I].ID;      //HighID will be highest ID number
  6783.     end;
  6784.    I:=Length(DBPreMixes)+1;
  6785.    SetLength(DBPreMixes,I);
  6786.    AddPreMix(I-1,HighID+1,NewPMix,TotalAmount);
  6787.    end;
  6788.   end
  6789.  else
  6790.   begin
  6791.   HighID:=0;
  6792.   DBPreMixes:=nil;
  6793.   SetLength(DBPreMixes,1);
  6794.   AddPreMix(0,HighID+1,NewPMix,TotalAmount);
  6795.   end;
  6796. //put all checkbox selected at end
  6797.  AreTheyChecked(NotChecked);
  6798.  m:=0;
  6799.  UnCheckedIngredient:=nil;
  6800.  for n := 1 to 16 do//16 downto 1 do
  6801.   begin
  6802.   if NotChecked[n]>0 then
  6803.    begin
  6804.    m:=m+1;
  6805.    SetLength(UnCheckedIngredient,m);
  6806.    UnCheckedIngredient[m-1]:=n;
  6807.    end;
  6808.   end;
  6809.  if m>1 then
  6810.   begin
  6811.   for n := 0 to m-2 do
  6812.    if UnCheckedIngredient[n]+1<>UnCheckedIngredient[n+1] then
  6813.     //Move Ingredient [n] to Ingredient [n+1]+1
  6814.     begin
  6815.     MoveIngredient(UnCheckedIngredient[n+1],UnCheckedIngredient[n]+1);
  6816.     UnCheckedIngredient[n+1]:=UnCheckedIngredient[n]+1;
  6817.     end;
  6818.   end;
  6819. //remove selected fields from TMR form
  6820.  for n:=1 to 16 do
  6821.   if Instant.ListCheckBox[17-n].Checked then
  6822.    begin
  6823.    Instant.RemoveFeedFromTMR1Click(Self);
  6824.    Instant.ListCheckBox[17-n].Checked:=False;
  6825.    end;
  6826. //put premix into TMR form
  6827.  n:=0;
  6828.  if Instant.ComboBox1.Text<>'' then n:=n+1;
  6829.  if Instant.ComboBox2.Text<>'' then n:=n+1;
  6830.  if Instant.ComboBox3.Text<>'' then n:=n+1;
  6831.  if Instant.ComboBox4.Text<>'' then n:=n+1;
  6832.  if Instant.ComboBox10.Text<>'' then n:=n+1;
  6833.  if Instant.ComboBox12.Text<>'' then n:=n+1;
  6834.  if Instant.ComboBox14.Text<>'' then n:=n+1;
  6835.  if Instant.ComboBox16.Text<>'' then n:=n+1;
  6836.  if Instant.ComboBox18.Text<>'' then n:=n+1;
  6837.  if Instant.ComboBox20.Text<>'' then n:=n+1;
  6838.  if Instant.ComboBox22.Text<>'' then n:=n+1;
  6839.  if Instant.ComboBox24.Text<>'' then n:=n+1;
  6840.  if Instant.ComboBox26.Text<>'' then n:=n+1;
  6841.  if Instant.ComboBox28.Text<>'' then n:=n+1;
  6842.  if Instant.ComboBox30.Text<>'' then n:=n+1;
  6843.  if Instant.ComboBox32.Text<>'' then n:=n+1;
  6844.  case n+1 of
  6845.  1: begin
  6846.     NewPremixes:=True;
  6847.     Instant.ComboBox5.Text:='Pre-Mix';
  6848.     Instant.ComboBox5Change(Instant);
  6849.     Instant.ComboBox1.Text:=SetNameP.Edit1.Text;
  6850.     Instant.ComboBox1Change(Instant);
  6851.     Instant.Edit6.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6852.     NewPremixes:=False;
  6853.     end;
  6854.  2: begin
  6855.     NewPremixes:=True;
  6856.     Instant.ComboBox6.Text:='Pre-Mix';
  6857.     Instant.ComboBox6Change(Instant);
  6858.     Instant.ComboBox2.Text:=SetNameP.Edit1.Text;
  6859.     Instant.ComboBox2Change(Instant);
  6860.     Instant.Edit7.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6861.     NewPremixes:=False;
  6862.     end;
  6863.  3: begin
  6864.     NewPremixes:=True;
  6865.     Instant.ComboBox7.Text:='Pre-Mix';
  6866.     Instant.ComboBox7Change(Instant);
  6867.     Instant.ComboBox3.Text:=SetNameP.Edit1.Text;
  6868.     Instant.ComboBox3Change(Instant);
  6869.     Instant.Edit8.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6870.     NewPremixes:=False;
  6871.     end;
  6872.  4: begin
  6873.     NewPremixes:=True;
  6874.     Instant.ComboBox8.Text:='Pre-Mix';
  6875.     Instant.ComboBox8Change(Instant);
  6876.     Instant.ComboBox4.Text:=SetNameP.Edit1.Text;
  6877.     Instant.ComboBox4Change(Instant);
  6878.     Instant.Edit9.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6879.     NewPremixes:=False;
  6880.     end;
  6881.  5: begin
  6882.     NewPremixes:=True;
  6883.     Instant.ComboBox9.Text:='Pre-Mix';
  6884.     Instant.ComboBox9Change(Instant);
  6885.     Instant.ComboBox10.Text:=SetNameP.Edit1.Text;
  6886.     Instant.ComboBox10Change(Instant);
  6887.     Instant.Edit13.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6888.     NewPremixes:=False;
  6889.     end;
  6890.  6: begin
  6891.     NewPremixes:=True;
  6892.     Instant.ComboBox11.Text:='Pre-Mix';
  6893.     Instant.ComboBox11Change(Instant);
  6894.     Instant.ComboBox12.Text:=SetNameP.Edit1.Text;
  6895.     Instant.ComboBox12Change(Instant);
  6896.     Instant.Edit16.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6897.     NewPremixes:=False;
  6898.     end;
  6899.  7: begin
  6900.     NewPremixes:=True;
  6901.     Instant.ComboBox13.Text:='Pre-Mix';
  6902.     Instant.ComboBox13Change(Instant);
  6903.     Instant.ComboBox14.Text:=SetNameP.Edit1.Text;
  6904.     Instant.ComboBox14Change(Instant);
  6905.     Instant.Edit18.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6906.     NewPremixes:=False;
  6907.     end;
  6908.  8: begin
  6909.     NewPremixes:=True;
  6910.     Instant.ComboBox15.Text:='Pre-Mix';
  6911.     Instant.ComboBox15Change(Instant);
  6912.     Instant.ComboBox16.Text:=SetNameP.Edit1.Text;
  6913.     Instant.ComboBox16Change(Instant);
  6914.     Instant.Edit20.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6915.     NewPremixes:=False;
  6916.     end;
  6917.  9: begin
  6918.     NewPremixes:=True;
  6919.     Instant.ComboBox17.Text:='Pre-Mix';
  6920.     Instant.ComboBox17Change(Instant);
  6921.     Instant.ComboBox18.Text:=SetNameP.Edit1.Text;
  6922.     Instant.ComboBox18Change(Instant);
  6923.     Instant.Edit22.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6924.     NewPremixes:=False;
  6925.     end;
  6926.  10: begin
  6927.     NewPremixes:=True;
  6928.     Instant.ComboBox19.Text:='Pre-Mix';
  6929.     Instant.ComboBox19Change(Instant);
  6930.     Instant.ComboBox20.Text:=SetNameP.Edit1.Text;
  6931.     Instant.ComboBox20Change(Instant);
  6932.     Instant.Edit24.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6933.     NewPremixes:=False;
  6934.     end;
  6935.  11: begin
  6936.     NewPremixes:=True;
  6937.     Instant.ComboBox21.Text:='Pre-Mix';
  6938.     Instant.ComboBox21Change(Instant);
  6939.     Instant.ComboBox22.Text:=SetNameP.Edit1.Text;
  6940.     Instant.ComboBox22Change(Instant);
  6941.     Instant.Edit26.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6942.     NewPremixes:=False;
  6943.     end;
  6944.  12: begin
  6945.     NewPremixes:=True;
  6946.     Instant.ComboBox23.Text:='Pre-Mix';
  6947.     Instant.ComboBox23Change(Instant);
  6948.     Instant.ComboBox24.Text:=SetNameP.Edit1.Text;
  6949.     Instant.ComboBox24Change(Instant);
  6950.     Instant.Edit28.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6951.     NewPremixes:=False;
  6952.     end;
  6953.  13: begin
  6954.     NewPremixes:=True;
  6955.     Instant.ComboBox25.Text:='Pre-Mix';
  6956.     Instant.ComboBox25Change(Instant);
  6957.     Instant.ComboBox26.Text:=SetNameP.Edit1.Text;
  6958.     Instant.ComboBox26Change(Instant);
  6959.     Instant.Edit1.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6960.     NewPremixes:=False;
  6961.     end;
  6962.  14: begin
  6963.     NewPremixes:=True;
  6964.     Instant.ComboBox27.Text:='Pre-Mix';
  6965.     Instant.ComboBox27Change(Instant);
  6966.     Instant.ComboBox28.Text:=SetNameP.Edit1.Text;
  6967.     Instant.ComboBox28Change(Instant);
  6968.     Instant.Edit2.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6969.     NewPremixes:=False;
  6970.     end;
  6971.  15: begin
  6972.     NewPremixes:=True;
  6973.     Instant.ComboBox29.Text:='Pre-Mix';
  6974.     Instant.ComboBox29Change(Instant);
  6975.     Instant.ComboBox30.Text:=SetNameP.Edit1.Text;
  6976.     Instant.ComboBox30Change(Instant);
  6977.     Instant.Edit3.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6978.     NewPremixes:=False;
  6979.     end;
  6980.  16: begin
  6981.     NewPremixes:=True;
  6982.     Instant.ComboBox31.Text:='Pre-Mix';
  6983.     Instant.ComboBox31Change(Instant);
  6984.     Instant.ComboBox32.Text:=SetNameP.Edit1.Text;
  6985.     Instant.ComboBox32Change(Instant);
  6986.     Instant.Edit4.Text:=FloatToStrF(TotalAmount,ffFixed,5,3);
  6987.     NewPremixes:=False;
  6988.     end;
  6989.  end;
  6990.  AutoPM:=False;
  6991.  end;
  6992.  end;
  6993. AutoSolveName:=False;}
  6994. end;
  6995.  
  6996. procedure TMain.MoveIngredient(FromIng,ToIng: Integer);
  6997. var
  6998. FromCategory,FromName,FromAmount: String;
  6999.  
  7000. begin
  7001. case FromIng of
  7002. 1: begin
  7003.    FromCategory:=Instant.ComboBox5.Text;
  7004.    FromName:=Instant.ComboBox1.Text;
  7005.    FromAmount:=Instant.Edit6.Text;
  7006.    Instant.ComboBox5.Text:='';
  7007.    Instant.ComboBox1.Text:='';
  7008.    Instant.Edit6.Text:='';
  7009.    end;
  7010. 2: begin
  7011.    FromCategory:=Instant.ComboBox6.Text;
  7012.    FromName:=Instant.ComboBox2.Text;
  7013.    FromAmount:=Instant.Edit7.Text;
  7014.    Instant.ComboBox6.Text:='';
  7015.    Instant.ComboBox2.Text:='';
  7016.    Instant.Edit7.Text:='';
  7017.    end;
  7018. 3: begin
  7019.    FromCategory:=Instant.ComboBox7.Text;
  7020.    FromName:=Instant.ComboBox3.Text;
  7021.    FromAmount:=Instant.Edit8.Text;
  7022.    Instant.ComboBox7.Text:='';
  7023.    Instant.ComboBox3.Text:='';
  7024.    Instant.Edit8.Text:='';
  7025.    end;
  7026. 4: begin
  7027.    FromCategory:=Instant.ComboBox8.Text;
  7028.    FromName:=Instant.ComboBox4.Text;
  7029.    FromAmount:=Instant.Edit9.Text;
  7030.    Instant.ComboBox8.Text:='';
  7031.    Instant.ComboBox4.Text:='';
  7032.    Instant.Edit9.Text:='';
  7033.    end;
  7034. 5: begin
  7035.    FromCategory:=Instant.ComboBox9.Text;
  7036.    FromName:=Instant.ComboBox10.Text;
  7037.    FromAmount:=Instant.Edit13.Text;
  7038.    Instant.ComboBox9.Text:='';
  7039.    Instant.ComboBox10.Text:='';
  7040.    Instant.Edit13.Text:='';
  7041.    end;
  7042. 6: begin
  7043.    FromCategory:=Instant.ComboBox11.Text;
  7044.    FromName:=Instant.ComboBox12.Text;
  7045.    FromAmount:=Instant.Edit16.Text;
  7046.    Instant.ComboBox11.Text:='';
  7047.    Instant.ComboBox12.Text:='';
  7048.    Instant.Edit16.Text:='';
  7049.    end;
  7050. 7: begin
  7051.    FromCategory:=Instant.ComboBox13.Text;
  7052.    FromName:=Instant.ComboBox14.Text;
  7053.    FromAmount:=Instant.Edit18.Text;
  7054.    Instant.ComboBox13.Text:='';
  7055.    Instant.ComboBox14.Text:='';
  7056.    Instant.Edit18.Text:='';
  7057.    end;
  7058. 8: begin
  7059.    FromCategory:=Instant.ComboBox15.Text;
  7060.    FromName:=Instant.ComboBox16.Text;
  7061.    FromAmount:=Instant.Edit20.Text;
  7062.    Instant.ComboBox15.Text:='';
  7063.    Instant.ComboBox16.Text:='';
  7064.    Instant.Edit20.Text:='';
  7065.    end;
  7066. 9: begin
  7067.    FromCategory:=Instant.ComboBox17.Text;
  7068.    FromName:=Instant.ComboBox18.Text;
  7069.    FromAmount:=Instant.Edit22.Text;
  7070.    Instant.ComboBox17.Text:='';
  7071.    Instant.ComboBox18.Text:='';
  7072.    Instant.Edit22.Text:='';
  7073.    end;
  7074. 10: begin
  7075.    FromCategory:=Instant.ComboBox19.Text;
  7076.    FromName:=Instant.ComboBox20.Text;
  7077.    FromAmount:=Instant.Edit24.Text;
  7078.    Instant.ComboBox19.Text:='';
  7079.    Instant.ComboBox20.Text:='';
  7080.    Instant.Edit24.Text:='';
  7081.    end;
  7082. 11: begin
  7083.    FromCategory:=Instant.ComboBox21.Text;
  7084.    FromName:=Instant.ComboBox22.Text;
  7085.    FromAmount:=Instant.Edit26.Text;
  7086.    Instant.ComboBox21.Text:='';
  7087.    Instant.ComboBox22.Text:='';
  7088.    Instant.Edit26.Text:='';
  7089.    end;
  7090. 12: begin
  7091.    FromCategory:=Instant.ComboBox23.Text;
  7092.    FromName:=Instant.ComboBox24.Text;
  7093.    FromAmount:=Instant.Edit28.Text;
  7094.    Instant.ComboBox23.Text:='';
  7095.    Instant.ComboBox24.Text:='';
  7096.    Instant.Edit28.Text:='';
  7097.    end;
  7098. 13: begin
  7099.    FromCategory:=Instant.ComboBox25.Text;
  7100.    FromName:=Instant.ComboBox26.Text;
  7101.    FromAmount:=Instant.Edit1.Text;
  7102.    Instant.ComboBox25.Text:='';
  7103.    Instant.ComboBox26.Text:='';
  7104.    Instant.Edit1.Text:='';
  7105.    end;
  7106. 14: begin
  7107.    FromCategory:=Instant.ComboBox27.Text;
  7108.    FromName:=Instant.ComboBox28.Text;
  7109.    FromAmount:=Instant.Edit2.Text;
  7110.    Instant.ComboBox27.Text:='';
  7111.    Instant.ComboBox28.Text:='';
  7112.    Instant.Edit2.Text:='';
  7113.    end;
  7114. 15: begin
  7115.    FromCategory:=Instant.ComboBox29.Text;
  7116.    FromName:=Instant.ComboBox30.Text;
  7117.    FromAmount:=Instant.Edit3.Text;
  7118.    Instant.ComboBox29.Text:='';
  7119.    Instant.ComboBox30.Text:='';
  7120.    Instant.Edit3.Text:='';
  7121.    end;
  7122. 16: begin
  7123.    FromCategory:=Instant.ComboBox31.Text;
  7124.    FromName:=Instant.ComboBox32.Text;
  7125.    FromAmount:=Instant.Edit4.Text;
  7126.    Instant.ComboBox31.Text:='';
  7127.    Instant.ComboBox32.Text:='';
  7128.    Instant.Edit4.Text:='';
  7129.    end;
  7130. end;
  7131. Instant.ListCheckBox[ToIng].Checked:=False;
  7132. case ToIng of
  7133. 1: begin
  7134.    Instant.ComboBox5.Text:=FromCategory;
  7135.    Instant.ComboBox5Change(Self);
  7136.    Instant.ComboBox1.Text:=FromName;
  7137.    Instant.ComboBox1Change(Self);
  7138.    Instant.Edit6.Text:=FromAmount;
  7139.    end;
  7140. 2: begin
  7141.    Instant.ComboBox6.Text:=FromCategory;
  7142.    Instant.ComboBox6Change(Self);
  7143.    Instant.ComboBox2.Text:=FromName;
  7144.    Instant.ComboBox2Change(Self);
  7145.    Instant.Edit7.Text:=FromAmount;
  7146.    end;
  7147. 3: begin
  7148.    Instant.ComboBox7.Text:=FromCategory;
  7149.    Instant.ComboBox7Change(Self);
  7150.    Instant.ComboBox3.Text:=FromName;
  7151.    Instant.ComboBox3Change(Self);
  7152.    Instant.Edit8.Text:=FromAmount;
  7153.    end;
  7154. 4: begin
  7155.    Instant.ComboBox8.Text:=FromCategory;
  7156.    Instant.ComboBox8Change(Self);
  7157.    Instant.ComboBox4.Text:=FromName;
  7158.    Instant.ComboBox4Change(Self);
  7159.    Instant.Edit9.Text:=FromAmount;
  7160.    end;
  7161. 5: begin
  7162.    Instant.ComboBox9.Text:=FromCategory;
  7163.    Instant.ComboBox9Change(Self);
  7164.    Instant.ComboBox10.Text:=FromName;
  7165.    Instant.ComboBox10Change(Self);
  7166.    Instant.Edit13.Text:=FromAmount;
  7167.    end;
  7168. 6: begin
  7169.    Instant.ComboBox11.Text:=FromCategory;
  7170.    Instant.ComboBox11Change(Self);
  7171.    Instant.ComboBox12.Text:=FromName;
  7172.    Instant.ComboBox12Change(Self);
  7173.    Instant.Edit16.Text:=FromAmount;
  7174.    end;
  7175. 7: begin
  7176.    Instant.ComboBox13.Text:=FromCategory;
  7177.    Instant.ComboBox13Change(Self);
  7178.    Instant.ComboBox14.Text:=FromName;
  7179.    Instant.ComboBox14Change(Self);
  7180.    Instant.Edit18.Text:=FromAmount;
  7181.    end;
  7182. 8: begin
  7183.    Instant.ComboBox15.Text:=FromCategory;
  7184.    Instant.ComboBox15Change(Self);
  7185.    Instant.ComboBox16.Text:=FromName;
  7186.    Instant.ComboBox16Change(Self);
  7187.    Instant.Edit20.Text:=FromAmount;
  7188.    end;
  7189. 9: begin
  7190.    Instant.ComboBox17.Text:=FromCategory;
  7191.    Instant.ComboBox17Change(Self);
  7192.    Instant.ComboBox18.Text:=FromName;
  7193.    Instant.ComboBox18Change(Self);
  7194.    Instant.Edit22.Text:=FromAmount;
  7195.    end;
  7196. 10: begin
  7197.    Instant.ComboBox19.Text:=FromCategory;
  7198.    Instant.ComboBox19Change(Self);
  7199.    Instant.ComboBox20.Text:=FromName;
  7200.    Instant.ComboBox20Change(Self);
  7201.    Instant.Edit24.Text:=FromAmount;
  7202.    end;
  7203. 11: begin
  7204.    Instant.ComboBox21.Text:=FromCategory;
  7205.    Instant.ComboBox21Change(Self);
  7206.    Instant.ComboBox22.Text:=FromName;
  7207.    Instant.ComboBox22Change(Self);
  7208.    Instant.Edit26.Text:=FromAmount;
  7209.    end;
  7210. 12: begin
  7211.    Instant.ComboBox23.Text:=FromCategory;
  7212.    Instant.ComboBox23Change(Self);
  7213.    Instant.ComboBox24.Text:=FromName;
  7214.    Instant.ComboBox24Change(Self);
  7215.    Instant.Edit28.Text:=FromAmount;
  7216.    end;
  7217. 13: begin
  7218.    Instant.ComboBox25.Text:=FromCategory;
  7219.    Instant.ComboBox25Change(Self);
  7220.    Instant.ComboBox26.Text:=FromName;
  7221.    Instant.ComboBox26Change(Self);
  7222.    Instant.Edit1.Text:=FromAmount;
  7223.    end;
  7224. 14: begin
  7225.    Instant.ComboBox27.Text:=FromCategory;
  7226.    Instant.ComboBox27Change(Self);
  7227.    Instant.ComboBox28.Text:=FromName;
  7228.    Instant.ComboBox28Change(Self);
  7229.    Instant.Edit2.Text:=FromAmount;
  7230.    end;
  7231. 15: begin
  7232.    Instant.ComboBox29.Text:=FromCategory;
  7233.    Instant.ComboBox29Change(Self);
  7234.    Instant.ComboBox30.Text:=FromName;
  7235.    Instant.ComboBox30Change(Self);
  7236.    Instant.Edit3.Text:=FromAmount;
  7237.    end;
  7238. 16: begin
  7239.    Instant.ComboBox31.Text:=FromCategory;
  7240.    Instant.ComboBox31Change(Self);
  7241.    Instant.ComboBox32.Text:=FromName;
  7242.    Instant.ComboBox32Change(Self);
  7243.    Instant.Edit4.Text:=FromAmount;
  7244.    end;
  7245. end;
  7246. end;
  7247.  
  7248. procedure TMain.SetIngPriceClick(Sender: TObject);
  7249. begin
  7250. if not Assigned(AlterFeedPrices) then
  7251.  Application.CreateForm(TAlterFeedPrices, AlterFeedPrices);
  7252. AlterFeedPrices.Show;
  7253. end;
  7254.  
  7255.  
  7256. end.
  7257.  
Advertisement
Add Comment
Please, Sign In to add comment