Advertisement
algodritmo

masterform

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