Beispiel #1
0
        //ViewController (askKPI) //TODO use Dialog Service instead
        //DataService (CreateNewTreeEntry)
        //DAL (LogTreeEstimate) //should be dataservice instead
        //SampleGroup (MinKPI/MaxKPI)
        public static TallyAction TallyThreeP(CountTree count, ISampleSelector sampler, SampleGroup sg, ITreeDataService dataService, IDialogService dialogService)
        {
            TallyAction action = new TallyAction(count)
            {
                TreeCount = 1,
            };

            var sgCode = sg.Code;
            var stCode = sg.Stratum.Code;
            var spCode = count.TreeDefaultValue.Species;
            int kpi    = 0;
            int?value  = dialogService.AskKPI((int)sg.MinKPI, (int)sg.MaxKPI, stCode, sgCode, spCode);

            if (value == null)
            {
                return(null);
            }
            else
            {
                kpi = value.Value;
            }

            if (kpi == -1)  //user entered sure to measure
            {
                var tree = dataService.CreateNewTreeEntry(count);
                tree.STM          = "Y";
                action.TreeRecord = tree;
            }
            else
            {
                action.TreeEstimate = dataService.LogTreeEstimate(count, kpi);
                action.KPI          = kpi;

                var result = ((IThreePSelector)sampler).Sample(kpi);
                if (result != SampleResult.C)
                {
                    var tree = dataService.CreateNewTreeEntry(count);
                    tree.KPI            = kpi;
                    tree.CountOrMeasure = result.ToString();
                    action.TreeRecord   = tree;
                }
            }

            return(action);
        }
        protected Tree TallyThreeP(Plot plot, CountTree count)
        {
            Tree tree;
            var  sg      = count.SampleGroup;
            var  sgCode  = sg.Code;
            var  stCode  = sg.Stratum.Code;
            var  spCode  = count.TreeDefaultValue.Species;
            var  sampler = SampleSelectorRepository.GetSamplerBySampleGroupCode(stCode, sgCode);

            int kpi   = 0;
            int?value = _dialogService.AskKPI((int)sg.MinKPI, (int)sg.MaxKPI, stCode, sgCode, spCode);

            if (value == null)
            {
                return(null); //user didn't enter valid value
            }
            else
            {
                kpi = value.Value;
            }

            //if kpi == -1 then tree is sure to measure
            if (kpi != -1)
            {
                var result = ((IThreePSelector)sampler).Sample(kpi);

                tree = DataService.CreateNewTreeEntry(plot, count, (result != SampleResult.C));
                tree.CountOrMeasure = result.ToString();
                tree.KPI            = kpi;
            }
            else//tree is sure to measure
            {
                tree     = DataService.CreateNewTreeEntry(plot, count, true);
                tree.STM = "Y";
            }

            tree.TreeCount = 1;

            return(tree);
        }