Exemplo n.º 1
0
        private List <Manure> transferManure(List <Husdyrgodkendelse.Goedning.Goedningsmaengde> manureAmount)
        {
            Manure        manure;
            List <Manure> ManureList = new List <Manure>();

            foreach (Husdyrgodkendelse.Goedning.Goedningsmaengde g in manureAmount)
            {
                int ManureTypeInt = translateManureType(g.Goedningstype.Navn);
                if ((ManureTypeInt == 12 || ManureTypeInt == 13 || ManureTypeInt == 14) && g.GoedningstypeNUdnyttelsesProcent == 0)
                {
                    message.Instance.addWarnings("Manglende udnyttelsesprocent for goedningstypen", "transferManure: cannot translate", 1);
                }
                manure = new Manure(g.KgN, ManureTypeInt, g.GoedningstypeNUdnyttelsesProcent);
                ManureList.Add(manure);
            }
            return(ManureList);
        }
Exemplo n.º 2
0
        public returnItems CalculateExisting(List <Areal> arealer, List <Husdyrgodkendelse.Goedning.Goedningsmaengde> goedningsmaengder, long bedriftID, string zipCode, int normYear, int version)
        {
            returnItems tilbage = new returnItems();

            try
            {
                List <Manure>           internalManureList           = new List <Manure>();
                List <StandardRotation> internalStandardRotationList = new List <StandardRotation>();
                foreach (Husdyrgodkendelse.Goedning.Goedningsmaengde manure in goedningsmaengder)
                {
                    if (manure.Goedningstype.Navn == null)
                    {
                        message.Instance.addWarnings("godnings navn er ikke modateget", "manure.Goedningstype.Navn is null", 1);
                    }
                    int    manureType = translateManureType(manure.Goedningstype.Navn);
                    Manure newManure  = new Manure(manure.KgN, manureType, manure.GoedningstypeNUdnyttelsesProcent);
                    internalManureList.Add(newManure);
                }
                foreach (Areal areal in arealer)
                {
                    if (areal.ArealType == null)
                    {
                        message.Instance.addWarnings("areal.ArealType er forkert", "areal.ArealTypn is null", 1);
                    }
                    if (areal.Saedskifte == null)
                    {
                        message.Instance.addWarnings("areal.Saedskifte er forkert ", "areal.Saedskifte is null", 1);
                    }
                    if (areal.Referencesaedskifte == null)
                    {
                        message.Instance.addWarnings("areal.Referencesaedskifte er forkert ", "areal.Referencesaedskifte is null", 1);
                    }
                    if (areal.ArealType == ArealTyper.Udbringning)
                    {
                        int soilType = translateSoilType(areal.Jordbundstype);
                        StandardRotation rotation = new StandardRotation(areal.Saedskifte, soilType, areal.Ha, areal.Referencesaedskifte, areal.Saedskifte, (int)areal.ArealType);
                        internalStandardRotationList.Add(rotation);
                    }
                }
                int cropyear        = -1;
                int rotationVersion = -1;
                int manureVersion   = -1;
                switch (version)
                {
                case 1: cropyear = 2007;
                    if (cropyear != normYear)
                    {
                        message.Instance.addWarnings("Det angivne år for udbytte- og gødnings-norm bør være 2007 i version 1", "normYear = " + normYear + " og burde være 2007 (version1)", 3);
                    }
                    rotationVersion = 1;
                    manureVersion   = 1;
                    break;

                case 2: cropyear = 2009;
                    if (cropyear != normYear)
                    {
                        message.Instance.addWarnings("Det angivne år for udbytte- og gødnings-norm bør være 2009 i version 2", "normYear = " + normYear + " og burde være 2009 (version2)", 3);
                    }
                    rotationVersion = 2;
                    manureVersion   = 2;
                    break;

                case 3: cropyear = 2009;
                    if (cropyear != normYear)
                    {
                        message.Instance.addWarnings("Det angivne år for udbytte- og gødnings-norm bør være 2009 i version 3", "normYear = " + normYear + " og burde være 2009 (version3)", 3);
                    }
                    rotationVersion = 2;
                    manureVersion   = 1;
                    break;

                case 4: cropyear    = normYear;
                    rotationVersion = 2;
                    manureVersion   = 2;
                    break;
                }
                scenario = new CalculateScenario(bedriftID, zipCode, cropyear, 1, 0, 0, manureVersion, internalManureList, internalStandardRotationList, rotationVersion, version);
                scenario.run();

                tilbage = scenario.getReturnData();
            }
            catch (Exception e)
            {
                int errorType = 0;

                for (int i = 0; i < message.Instance.getwarningsList().Count(); i++)
                {
                    if (message.Instance.getwarningsList()[i].ErrorType == 1 || message.Instance.getwarningsList()[i].ErrorType == 2)
                    {
                        errorType = message.Instance.getwarningsList()[i].ErrorType;
                    }
                }
                message.Instance.addWarnings("Kritisk systemfejl", "On global scale " + e.Message.ToString(), 4 + errorType);
                tilbage.NLeach_KgN_ha_total = -1;
                tilbage.NLeach_mgN_l_total  = -1;
                tilbage.arealData           = new List <FarmNData>();
            }
            finally
            {
                message.Instance.WriteToFile();
                tilbage.errorMessages = message.Instance.getwarningsList();
                if (sqlconn != null)
                {
                    sqlconn.Close();
                }
            }

            return(tilbage);
        }