private void OnSample(TallyAction action, CountTreeVM count, bool isInsurance)
        {
            TreeVM tree = Unit.CreateNewTreeEntry(count);
            tree.CountOrMeasure = (isInsurance) ? "I" : "M";

            action.TreeRecord = tree;

            if (!isInsurance)
            {
                this.ViewController.SignalMeasureTree(true);
            }
            else
            {
                this.ViewController.SignalInsuranceTree();
            }

            this.ViewController.ShowCruiserSelection(tree);

            tree.TrySave();
            Unit.AddNonPlotTree(tree);

            if (!isInsurance && View.AskEnterMeasureTreeData())
            {
                this.View.GotoTreePage();
                this.View.TreeViewMoveLast();
            }
        }
        public void OnTally(CountTreeVM count)
        {
            TallyAction action = new TallyAction(count);
            SampleGroupDO sg = count.SampleGroup;

            //if doing a manual tally create a tree and jump out
            //if ((sg.TallyMethod & CruiseDAL.Enums.TallyMode.Manual) == CruiseDAL.Enums.TallyMode.Manual)
            //{
            //    TreeVM newTree;
            //    newTree = Controller.CreateNewTreeEntry(count, null, true); //create measure tree
            //    count.TreeCount += sg.SamplingFrequency;                    //increment tree count on tally
            //    this.Controller.TrySaveTree(newTree);
            //    Controller.AddTallyAction(action);
            //    Controller.OnTally();
            //    return;
            //}

            SampleSelecter sampler = (SampleSelecter)count.SampleGroup.Sampler;
            if (count.SampleGroup.Stratum.Is3P)//threeP sampling
            {
                int kpi = 0;
                int? value = ViewController.AskKPI((int)count.SampleGroup.MinKPI, (int)count.SampleGroup.MaxKPI);
                if (value == null)
                {
                    return;
                }
                else
                {
                    kpi = value.Value;
                }
                if (kpi == -1)  //user enterted sure to measure
                {
                    TreeVM tree;
                    tree = Unit.CreateNewTreeEntry(count);
                    tree.STM = "Y";
                    tree.TrySave();
                    Unit.AddNonPlotTree(tree);
                    action.TreeRecord = tree;
                }
                else
                {
                    action.TreeEstimate = count.LogTreeEstimate(kpi);
                    action.KPI = kpi;
                    count.SumKPI += kpi;

                    ThreePItem item = (ThreePItem)((ThreePSelecter)sampler).NextItem();
                    if (item != null && kpi > item.KPI)
                    {
                        if (sampler.IsSelectingITrees)
                        {
                            item.IsInsuranceItem = sampler.InsuranceCounter.Next();
                        }
                        this.OnSample(action, count, kpi, item.IsInsuranceItem);
                    }
                }
            }
            else//non 3P sampling (STR)
            {
                boolItem item = (boolItem)sampler.NextItem();
                //If we recieve nothing from from the sampler, we don't have a sample
                if (item != null)//&& (item.IsSelected || item.IsInsuranceItem))
                {
                    this.OnSample(action, count, (item != null && item.IsInsuranceItem));
                }
            }

            count.TreeCount++;
            Unit.TallyHistoryBuffer.Add(action);
        }