Beispiel #1
0
        // This routine will typically be triggered after soil tests for a particular field have been updated
        // This routine will recalculate for all crops in a field the nutrients all that are dependant on the soil tests
        public void RecalcCropsSoilTestMessagesByField(string fieldName)
        {
            CalculateCropRequirementRemoval ccrr = new CalculateCropRequirementRemoval(_ud, _sd);

            //iterate through the crops and update the crop requirements
            List <FieldCrop> fieldCrops = _ud.GetFieldCrops(fieldName);

            if (fieldCrops.Count > 0)
            {
                foreach (var _crop in fieldCrops)
                {
                    CropType  crpTyp = new CropType();
                    FieldCrop cf     = _ud.GetFieldCrop(fieldName, _crop.id);
                    if (cf.cropId != null)
                    {
                        Crop cp = _sd.GetCrop(Convert.ToInt32(cf.cropId));
                        crpTyp = _sd.GetCropType(cp.croptypeid);
                    }
                    else
                    {
                        crpTyp.modifynitrogen = false;
                    }

                    CropRequirementRemoval crr = new CropRequirementRemoval();
                    ccrr.cropid             = Convert.ToInt16(_crop.cropId);
                    ccrr.previousCropid     = _crop.prevCropId;
                    ccrr.yield              = _crop.yield;
                    ccrr.crudeProtien       = _crop.crudeProtien;
                    ccrr.coverCropHarvested = _crop.coverCropHarvested;
                    ccrr.fieldName          = fieldName;

                    crr = ccrr.GetCropRequirementRemoval();

                    if (!crpTyp.modifynitrogen)
                    {
                        cf.reqN = crr.N_Requirement;
                    }
                    cf.reqP2o5 = crr.P2O5_Requirement;
                    cf.reqK2o  = crr.K2O_Requirement;
                    cf.remN    = crr.N_Removal;
                    cf.remP2o5 = crr.P2O5_Removal;
                    cf.remK2o  = crr.K2O_Removal;

                    _ud.UpdateFieldCrop(fieldName, cf);
                }
            }
        }