Beispiel #1
0
        public IActionResult SoilTest(SoilTestViewModel fvm)
        {
            fvm.tstOptions = new List <SelectListItem>();
            fvm.tstOptions = _sd.GetSoilTestMethodsDll().ToList();

            if (fvm.buttonPressed == "MethodChange")
            {
                ModelState.Clear();
                FarmDetails fd = _ud.FarmDetails();
                fd.testingMethod = fvm.selTstOption == "select" ? string.Empty : fvm.selTstOption;
                _ud.UpdateFarmDetails(fd);
                fvm.testSelected = string.IsNullOrEmpty(fd.testingMethod) ? false : true;
                List <Field> fl = _ud.GetFields();

                //update fields with convert STP and STK
                _ud.UpdateSTPSTK(fl);

                //update the Nutrient calculations with the new/changed soil test data
                Utility.ChemicalBalanceMessage cbm = new Utility.ChemicalBalanceMessage(_ud, _sd);
                cbm.RecalcCropsSoilTestMessagesByFarm();

                RedirectToAction("SoilTest", "Soil");
            }
            return(View(fvm));
        }
        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));
        }
Beispiel #3
0
        private Task <PrevYearManureApplViewModel> GetPrevYearManureAsync(string fldName)
        {
            PrevYearManureApplViewModel manureVM = new PrevYearManureApplViewModel();

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

            Field fld = _ud.GetFieldDetails(fldName);

            manureVM.display = false;
            if (fld.crops != null)
            {
                if (fld.crops.Count() > 0)
                {
                    manureVM.display = _sd.WasManureAddedInPreviousYear(fld.prevYearManureApplicationFrequency);
                    if (manureVM.display)
                    {
                        manureVM.fldName = fldName;
                        if (fld.prevYearManureApplicationNitrogenCredit != null)
                        {
                            manureVM.nitrogen = fld.prevYearManureApplicationNitrogenCredit;
                        }
                        else
                        {
                            // lookup default Nitrogen credit
                            manureVM.nitrogen = calculator.calcPrevYearManureApplDefault(fldName);
                        }
                    }
                    else
                    {
                        fld.prevYearManureApplicationNitrogenCredit = null;
                        _ud.UpdateField(fld);
                    }
                }
                else
                {
                    fld.prevYearManureApplicationNitrogenCredit = null;
                    _ud.UpdateField(fld);
                }
            }
            else
            {
                //reset the nitrogen credit to null
                fld.prevYearManureApplicationNitrogenCredit = null;
                _ud.UpdateField(fld);
            }
            return(Task.FromResult(manureVM));
        }
Beispiel #4
0
        public IActionResult SoilTestDetails(SoilTestDetailsViewModel tvm)
        {
            decimal nmbr;

            if (ModelState.IsValid)
            {
                if (!Decimal.TryParse(tvm.dispNO3H, out nmbr))
                {
                    ModelState.AddModelError("dispNO3H", "Numbers only.");
                }
                else
                {
                    if (nmbr < 0)
                    {
                        ModelState.AddModelError("dispNO3H", "Invalid.");
                    }
                }
                if (!Decimal.TryParse(tvm.dispP, out nmbr))
                {
                    ModelState.AddModelError("dispP", "Numbers only.");
                }
                else
                {
                    if (nmbr < 0)
                    {
                        ModelState.AddModelError("dispP", "Invalid.");
                    }
                }
                if (!Decimal.TryParse(tvm.dispK, out nmbr))
                {
                    ModelState.AddModelError("dispK", "Numbers only.");
                }
                else
                {
                    if (nmbr < 0)
                    {
                        ModelState.AddModelError("dispK", "Invalid.");
                    }
                }
                if (!Decimal.TryParse(tvm.dispPH, out nmbr))
                {
                    ModelState.AddModelError("dispPH", "Numbers only.");
                }
                else
                {
                    if (nmbr < 0 ||
                        nmbr > 14)
                    {
                        ModelState.AddModelError("dispPH", "Invalid.");
                    }
                }
                if (!ModelState.IsValid)
                {
                    return(View(tvm));
                }

                Field fld = _ud.GetFieldDetails(tvm.fieldName);
                if (fld.soilTest == null)
                {
                    fld.soilTest = new SoilTest();
                }
                fld.soilTest.sampleDate        = Convert.ToDateTime(tvm.sampleDate);
                fld.soilTest.ValP              = Convert.ToDecimal(tvm.dispP);
                fld.soilTest.valK              = Convert.ToDecimal(tvm.dispK);
                fld.soilTest.valNO3H           = Convert.ToDecimal(tvm.dispNO3H);
                fld.soilTest.valPH             = Convert.ToDecimal(tvm.dispPH);
                fld.soilTest.ConvertedKelownaK = _soilTestConversions.GetConvertedSTK(_ud.FarmDetails()?.testingMethod, fld.soilTest);
                fld.soilTest.ConvertedKelownaP = _soilTestConversions.GetConvertedSTP(_ud.FarmDetails()?.testingMethod, fld.soilTest);

                _ud.UpdateFieldSoilTest(fld);

                //update the Nutrient calculations with the new/changed soil test data
                Utility.ChemicalBalanceMessage cbm = new Utility.ChemicalBalanceMessage(_ud, _sd);
                cbm.RecalcCropsSoilTestMessagesByField(tvm.fieldName);

                string target = "#test";
                string url    = Url.Action("RefreshTestList", "Soil");
                return(Json(new { success = true, url = url, target = target }));
            }
            return(View(tvm));
        }