public static object GetTreeTDVList(this DAL database, TreeVM tree)
        {
            if (tree == null) { return EMPTY_SPECIES_LIST; }
            if (tree.Stratum == null)
            {
                if (database.GetRowCount("CuttingUnitStratum", "WHERE CuttingUnit_CN = ?", tree.CuttingUnit_CN) == 1)
                {
                    tree.Stratum = database.From<StratumVM>()
                        .Join("CuttingUnitStratum", "USING (Stratum_CN)").Where("CuttingUnit_CN = ?")
                        .Read(tree.CuttingUnit_CN).FirstOrDefault();
                }
                else
                {
                    return EMPTY_SPECIES_LIST;
                }
            }

            if (tree.SampleGroup == null)
            {
                if (database.GetRowCount("SampleGroup", "WHERE Stratum_CN = ?", tree.Stratum_CN) == 1)
                {
                    tree.SampleGroup = database.From<SampleGroupDO>()
                        .Where("Stratum_CN = ?").Read(tree.Stratum_CN).FirstOrDefault();
                }
                if (tree.SampleGroup == null)
                {
                    return EMPTY_SPECIES_LIST;
                }
            }

            return database.From<TreeDefaultValueDO>()
                .Join("SampleGroupTreeDefaultValue", "USING (TreeDefaultValue_CN)")
                .Where("SampleGroup_CN = ?").Read(tree.SampleGroup_CN).ToArray();
        }
        public static void SetTreeTDV(TreeVM tree, TreeDefaultValueDO tdv)
        {
            tree.TreeDefaultValue = tdv;
            if (tdv != null)
            {
                tree.Species = tdv.Species;

                tree.LiveDead = tdv.LiveDead;
                tree.Grade = tdv.TreeGrade;
                tree.FormClass = tdv.FormClass;
                tree.RecoverablePrimary = tdv.Recoverable;
                //tree.HiddenPrimary = tdv.HiddenPrimary; //#367
            }
            else
            {
                //tree.Species = string.Empty;
                //tree.LiveDead = string.Empty;
                //tree.Grade = string.Empty;
                //tree.FormClass = 0;
                //tree.RecoverablePrimary = 0;
                //tree.HiddenPrimary = 0;
            }
        }
 protected void UpdateSpeciesColumn(TreeVM tree, DataGridViewComboBoxCell cell)
 {
     if (cell == null) { return; }
     cell.DataSource = ApplicationController.Database.GetTreeTDVList(tree);
 }
 //private void TreeDataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
 //{
 //    var tree = e.Row.DataBoundItem as TreeVM;
 //    if (tree == null) { e.Cancel = true; return; }
 //    e.Cancel = !this.TryDeleteTree(tree);
 //}
 protected void UpdateSampleGroupColumn(TreeVM tree, DataGridViewComboBoxCell cell)
 {
     if (cell == null) { return; }
     cell.DataSource = ApplicationController.Database.GetSampleGroupsByStratum(tree.Stratum_CN);
 }
 protected bool TrySaveTree(TreeVM tree)
 {
     try
     {
         tree.Save();
         return true;
     }
     catch (Exception e)
     {
         MessageBox.Show("Unable to save tree. Ensure Tree Number, Sample Group and Stratum are valid");
         //this.HandleNonCriticalException(e, "Unable to save tree. Ensure Tree Number, Sample Group and Stratum are valid");
         return false;
     }
 }
 protected bool TryDeleteTree(TreeVM tree)
 {
     try
     {
         tree.Delete();
         return true;
     }
     catch
     {
         return false;
     }
 }