public int GetConvertedSTK(SoilTest soilTest)
        {
            int convertedK = 0;

            try
            {
                //get soil test method selected by user
                FarmDetails fd = _ud.FarmDetails();

                if (fd.testingMethod == null)
                {
                    fd.testingMethod = _sd.GetDefaultSoilTestMethod();
                }

                var soilTestMethod = _sd.GetSoilTestMethodById(fd.testingMethod);

                convertedK = Convert.ToInt16(Decimal.Multiply(soilTestMethod.ConvertToKelownaK, soilTest.valK));
            }
            catch (Exception ex)
            {
                // display error
                throw;
            }

            return(convertedK);
        }
        public int GetConvertedSTP(SoilTest soilTest)
        {
            int convertedP = 0;

            try
            {
                //get soil test method selected by user
                FarmDetails fd = _ud.FarmDetails();

                if (fd.testingMethod == null)
                {
                    fd.testingMethod = _sd.GetDefaultSoilTestMethod();
                }

                SoilTestMethod soilTestMethod = _sd.GetSoilTestMethodById(fd.testingMethod);

                if (soilTest.valPH >= 7.2M) //ph of 7.2 is a constant boundary
                {
                    convertedP = Convert.ToInt16(Decimal.Multiply(soilTestMethod.ConvertToKelownaPHGreaterThanEqual72, soilTest.ValP));
                }
                else
                {
                    convertedP = Convert.ToInt16(Decimal.Multiply(soilTestMethod.ConvertToKelownaPHLessThan72, soilTest.ValP));
                }
            }
            catch (Exception ex)
            {
                // display error
                throw;
            }

            return(convertedP);
        }
        public int GetConvertedSTK(string selectedSoilTestMethod, SoilTest soilTest)
        {
            //get soil test method selected by user
            if (selectedSoilTestMethod == null)
            {
                selectedSoilTestMethod = _sd.GetDefaultSoilTestMethod();
            }

            var retreivedSoilTestMethod = _sd.GetSoilTestMethodById(selectedSoilTestMethod);

            var convertedK = Convert.ToInt16(Decimal.Multiply(retreivedSoilTestMethod.ConvertToKelownaK, soilTest.valK));

            return(convertedK);
        }
        public int GetConvertedSTP(string selectedSoilTestMethod, SoilTest soilTest)
        {
            int convertedP = 0;

            //get soil test method selected by user
            if (selectedSoilTestMethod == null)
            {
                selectedSoilTestMethod = _sd.GetDefaultSoilTestMethod();
            }

            var retreivedSoilTestMethod = _sd.GetSoilTestMethodById(selectedSoilTestMethod);

            if (soilTest.valPH >= 7.2M) //ph of 7.2 is a constant boundary
            {
                convertedP = Convert.ToInt16(Decimal.Multiply(retreivedSoilTestMethod.ConvertToKelownaPHGreaterThanEqual72, soilTest.ValP));
            }
            else
            {
                convertedP = Convert.ToInt16(Decimal.Multiply(retreivedSoilTestMethod.ConvertToKelownaPHLessThan72, soilTest.ValP));
            }

            return(convertedP);
        }
        public int GetConvertedSTK(string selectedSoilTestMethod, SoilTest soilTest)
        {
            int convertedK = 0;

            try
            {
                //get soil test method selected by user
                if (selectedSoilTestMethod == null)
                {
                    selectedSoilTestMethod = _sd.GetDefaultSoilTestMethod();
                }

                var retreivedSoilTestMethod = _sd.GetSoilTestMethodById(selectedSoilTestMethod);

                convertedK = Convert.ToInt16(Decimal.Multiply(retreivedSoilTestMethod.ConvertToKelownaK, soilTest.valK));
            }
            catch (Exception ex)
            {
                // display error
                throw;
            }

            return(convertedK);
        }
Esempio n. 6
0
        public async Task <string> RenderSummary()
        {
            string crpName = string.Empty;

            Utility.SoilTestConversions stc = new SoilTestConversions(_ud, _sd);

            ReportSummaryViewModel rvm = new ReportSummaryViewModel();

            rvm.testMethod = string.IsNullOrEmpty(_ud.FarmDetails().testingMethod) ? "Not Specified" : _sd.GetSoilTestMethod(_ud.FarmDetails().testingMethod);
            rvm.year       = _ud.FarmDetails().year;

            FarmDetails fd = _ud.FarmDetails();

            rvm.tests = new List <ReportSummaryTest>();

            List <Field> flds = _ud.GetFields();

            foreach (var m in flds)
            {
                ReportSummaryTest dc = new ReportSummaryTest();
                dc.fieldName = m.fieldName;
                if (m.soilTest != null)
                {
                    dc.sampleDate       = m.soilTest.sampleDate.ToString("MMM-yyyy");
                    dc.nitrogen         = m.soilTest.valNO3H.ToString();
                    dc.phosphorous      = m.soilTest.ValP.ToString();
                    dc.potassium        = m.soilTest.valK.ToString();
                    dc.pH               = m.soilTest.valPH.ToString();
                    dc.phosphorousRange = _sd.SoilTestRating("phosphorous", stc.GetConvertedSTP(m.soilTest));
                    dc.potassiumRange   = _sd.SoilTestRating("potassium", stc.GetConvertedSTK(m.soilTest));
                }
                else
                {
                    DefaultSoilTest dt = _sd.GetDefaultSoilTest();
                    SoilTest        st = new SoilTest();
                    st.valPH             = dt.pH;
                    st.ValP              = dt.phosphorous;
                    st.valK              = dt.potassium;
                    st.valNO3H           = dt.nitrogen;
                    st.ConvertedKelownaP = dt.convertedKelownaP;
                    st.ConvertedKelownaK = dt.convertedKelownaK;

                    dc.sampleDate       = "Default Values";
                    dc.nitrogen         = dt.nitrogen.ToString();
                    dc.phosphorous      = dt.phosphorous.ToString();
                    dc.potassium        = dt.potassium.ToString();
                    dc.pH               = dt.pH.ToString();
                    dc.phosphorousRange = _sd.SoilTestRating("phosphorous", stc.GetConvertedSTP(st));
                    dc.potassiumRange   = _sd.SoilTestRating("potassium", stc.GetConvertedSTK(st));
                }
                dc.fieldCrops = null;

                List <FieldCrop> crps = _ud.GetFieldCrops(m.fieldName);
                if (crps != null)
                {
                    foreach (var c in crps)
                    {
                        crpName       = string.IsNullOrEmpty(c.cropOther) ? _sd.GetCrop(Convert.ToInt32(c.cropId)).cropname : c.cropOther;
                        dc.fieldCrops = string.IsNullOrEmpty(dc.fieldCrops) ? crpName : dc.fieldCrops + "\n" + crpName;
                    }
                }
                rvm.tests.Add(dc);
            }


            var result = await _viewRenderService.RenderToStringAsync("~/Views/Report/ReportSummary.cshtml", rvm);

            return(result);
        }