internal TreeVM CreateNewTreeEntryInternal(StratumModel stratum
            , SampleGroupModel sg
            , TreeDefaultValueDO tdv
            , bool isMeasure)
        {
            TreeVM newTree = new TreeVM(this.DAL);
            newTree.TreeCount = 0;
            newTree.CountOrMeasure = (isMeasure) ? "M" : "C";
            newTree.CuttingUnit = this;

            if (sg != null)
            {
                newTree.SampleGroup = sg;
                if (tdv == null)
                {
                    if (sg.TreeDefaultValues.IsPopulated == false)
                    {
                        sg.TreeDefaultValues.Populate();
                    }
                    if (sg.TreeDefaultValues.Count == 1)
                    {
                        tdv = sg.TreeDefaultValues[0];
                    }
                }
            }
            if (stratum != null) { newTree.Stratum = stratum; }
            if (tdv != null)
            {
                newTree.SetTreeTDV(tdv);
            }

            newTree.Validate();
            //newTree.Save();

            return newTree;
        }
 //protected bool ProcessSampleGroupChanging(TreeVM tree, SampleGroupVM newSG)
 //{
 //    if (tree == null || newSG == null) { return false; }
 //    if (tree.SampleGroup != null)
 //    {
 //        if (MessageBox.Show("You are changing the Sample Group of a tree, are you sure you want to do this?", "!", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2)
 //            == DialogResult.No)
 //        {
 //            return false;
 //        }
 //        else
 //        {
 //            this.AppController._cDal.LogMessage(String.Format("Tree Sample Group Changed (Cu:{0} St:{1} Sg:{2} -> {3} Tdv_CN:{4} T#: {5}",
 //                tree.CuttingUnit.Code,
 //                tree.Stratum.Code,
 //                (tree.SampleGroup != null) ? tree.SampleGroup.Code : "?",
 //                newSG.Code,
 //                (tree.TreeDefaultValue != null) ? tree.TreeDefaultValue.TreeDefaultValue_CN.ToString() : "?",
 //                tree.TreeNumber), "high");
 //            tree.SampleGroup = newSG;
 //        }
 //    }
 //    else
 //    {
 //        tree.SampleGroup = newSG;
 //    }
 //    if (tree.TreeDefaultValue != null)
 //    {
 //        var hasTDV = tree.DAL.ExecuteScalar<bool>("SELECT count(1) " +
 //            "FROM SampleGroupTreeDefaultValue " +
 //            "WHERE TreeDefaultValue_CN = ? AND SampleGroup_CN"
 //            , tree.TreeDefaultValue_CN, newSG.SampleGroup_CN);
 //        if (!hasTDV)
 //        {
 //            tree.SetTreeTDV(null);
 //        }
 //    }
 //    return tree.TrySave();
 //}
 protected bool ProcessSpeciesChanged(TreeVM tree, TreeDefaultValueDO tdv)
 {
     if (tree == null) { return true; }
     if (tree.TreeDefaultValue == tdv) { return true; }
     tree.SetTreeTDV(tdv);
     return tree.TrySave();
 }
 public bool HandleSpeciesChanged(TreeVM tree, TreeDefaultValueDO tdv)
 {
     if (tree == null) { return true; }
     //if (tree.TreeDefaultValue == tdv) { return true; }
     tree.SetTreeTDV(tdv);
     return tree.TrySave();
 }