private Task <GetSoilTestNitrateOverrideViewModel> GetSoilTestNitrateOverrideAsync(string fldName)
        {
            GetSoilTestNitrateOverrideViewModel soilvm = new GetSoilTestNitrateOverrideViewModel();

            // get the current associated value for nitrogen credit.  Note, can be null
            SERVERAPI.Utility.ChemicalBalanceMessage calculator = new Utility.ChemicalBalanceMessage(_ud, _sd);

            FarmDetails farmdtl = _ud.FarmDetails();
            Field       fld     = _ud.GetFieldDetails(fldName);

            soilvm.display = false;

            if ((fld.crops != null) && (fld.soilTest != null))
            {
                if (fld.crops.Count() > 0)
                {
                    soilvm.display = _sd.IsNitrateCreditApplicable(farmdtl.farmRegion, fld.soilTest.sampleDate, Convert.ToInt16(farmdtl.year));
                    if (soilvm.display)
                    {
                        soilvm.fldName = fldName;
                        if (fld.SoilTestNitrateOverrideNitrogenCredit != null)
                        {
                            soilvm.nitrogen = Math.Round(Convert.ToDecimal(fld.SoilTestNitrateOverrideNitrogenCredit));
                        }
                        else
                        {
                            // lookup default Nitrogen credit
                            soilvm.nitrogen = Math.Round(fld.soilTest.valNO3H * _sd.GetSoilTestNitratePPMToPoundPerAcreConversionFactor());
                        }
                    }
                    else
                    {
                        fld.SoilTestNitrateOverrideNitrogenCredit = null;
                        _ud.UpdateField(fld);
                    }
                }
                else
                {
                    fld.SoilTestNitrateOverrideNitrogenCredit = null;
                    _ud.UpdateField(fld);
                }
            }
            else
            {
                fld.SoilTestNitrateOverrideNitrogenCredit = null;
                _ud.UpdateField(fld);
            }
            return(Task.FromResult(soilvm));
        }
示例#2
0
        public ChemicalBalances GetChemicalBalances(string fldName)
        {
            displayBalances = false;

            chemicalBalances.balance_AgrN     = 0;
            chemicalBalances.balance_AgrP2O5  = 0;
            chemicalBalances.balance_AgrK2O   = 0;
            chemicalBalances.balance_CropN    = 0;
            chemicalBalances.balance_CropP2O5 = 0;
            chemicalBalances.balance_CropK2O  = 0;

            List <FieldCrop> crps = _ud.GetFieldCrops(fldName);

            foreach (var c in crps)
            {
                chemicalBalances.balance_AgrN     -= Convert.ToInt64(c.reqN);
                chemicalBalances.balance_AgrP2O5  -= Convert.ToInt64(c.reqP2o5);
                chemicalBalances.balance_AgrK2O   -= Convert.ToInt64(c.reqK2o);
                chemicalBalances.balance_CropN    -= Convert.ToInt64(c.remN);
                chemicalBalances.balance_CropP2O5 -= Convert.ToInt64(c.remP2o5);
                chemicalBalances.balance_CropK2O  -= Convert.ToInt64(c.remK2o);
            }

            List <NutrientManure> manures = _ud.GetFieldNutrientsManures(fldName);

            foreach (var m in manures)
            {
                chemicalBalances.balance_AgrN     += Convert.ToInt64(m.yrN);
                chemicalBalances.balance_AgrP2O5  += Convert.ToInt64(m.yrP2o5);
                chemicalBalances.balance_AgrK2O   += Convert.ToInt64(m.yrK2o);
                chemicalBalances.balance_CropN    += Convert.ToInt64(m.ltN);
                chemicalBalances.balance_CropP2O5 += Convert.ToInt64(m.ltP2o5);
                chemicalBalances.balance_CropK2O  += Convert.ToInt64(m.ltK2o);
            }

            List <NutrientFertilizer> fertilizers = _ud.GetFieldNutrientsFertilizers(fldName);

            foreach (var f in fertilizers)
            {
                chemicalBalances.balance_AgrN     += Convert.ToInt64(f.fertN);
                chemicalBalances.balance_AgrP2O5  += Convert.ToInt64(f.fertP2o5);
                chemicalBalances.balance_AgrK2O   += Convert.ToInt64(f.fertK2o);
                chemicalBalances.balance_CropN    += Convert.ToInt64(f.fertN);
                chemicalBalances.balance_CropP2O5 += Convert.ToInt64(f.fertP2o5);
                chemicalBalances.balance_CropK2O  += Convert.ToInt64(f.fertK2o);
            }

            List <NutrientOther> others = _ud.GetFieldNutrientsOthers(fldName);

            foreach (var m in others)
            {
                chemicalBalances.balance_AgrN     += Convert.ToInt64(m.ltN);
                chemicalBalances.balance_AgrP2O5  += Convert.ToInt64(m.ltP2o5);
                chemicalBalances.balance_AgrK2O   += Convert.ToInt64(m.ltK);
                chemicalBalances.balance_CropN    += Convert.ToInt64(m.yrN);
                chemicalBalances.balance_CropP2O5 += Convert.ToInt64(m.yrP2o5);
                chemicalBalances.balance_CropK2O  += Convert.ToInt64(m.yrK);
            }

            // include the Nitrogren credit as a result of adding manure in previous years
            // lookup default Nitrogen credit.
            Field fld = _ud.GetFieldDetails(fldName);

            if (fld.crops != null)
            {
                if ((fld.prevYearManureApplicationNitrogenCredit != null) && (fld.crops.Count() > 0))
                {
                    chemicalBalances.balance_AgrN += Convert.ToInt32(fld.prevYearManureApplicationNitrogenCredit);
                }
                else
                {
                    // accomodate previous version of farm data - lookup default Nitrogen credit.
                    chemicalBalances.balance_AgrN += calcPrevYearManureApplDefault(fldName);
                }
                if (fld.soilTest != null)
                {
                    if (_sd.IsNitrateCreditApplicable(_ud.FarmDetails().farmRegion, fld.soilTest.sampleDate, Convert.ToInt16(_ud.FarmDetails().year)))
                    {
                        if ((fld.SoilTestNitrateOverrideNitrogenCredit != null) && (fld.crops.Count() > 0))
                        {
                            chemicalBalances.balance_AgrN += Convert.ToInt32(Math.Round(Convert.ToDecimal(fld.SoilTestNitrateOverrideNitrogenCredit)));
                        }
                        else
                        {
                            // accomodate previous version of farm data - lookup default Nitrogen credit.
                            chemicalBalances.balance_AgrN += Convert.ToInt32(Math.Round(calcSoitTestNitrateDefault(fldName)));
                        }
                    }
                }
            }

            if (crps.Count > 0) //display balance messages when at least one Crop has been added
            {
                displayBalances = true;
            }

            return(chemicalBalances);
        }