public static List<PlotDO> ReadyByUnitStratum(DatastoreRedux dal, String unit, String stratum)
        {
            if (dal == null) { return null; }
            if (String.IsNullOrEmpty(unit))
            {
                return dal.From<PlotDO>()
                    .Join("Stratum", "USING (Stratum_CN)")
                    .Where("Stratum.Code = ?")
                    .Read(stratum).ToList();

                //.Read<PlotDO>("JOIN Stratum WHERE Plot.Stratum_CN = Stratum.Stratum_CN AND Stratum.Code = ?;", (object)stratum);
            }
            else if (String.IsNullOrEmpty(stratum))
            {
                return dal.From<PlotDO>()
                    .Join("CuttingUnit", "USING (CuttingUnit_CN)")
                    .Where("CuttingUnit.Code = ?")
                    .Read(unit).ToList();

                //.Read<PlotDO>("JOIN CuttingUnit WHERE Plot.CuttingUnit_CN = CuttingUnit.CuttingUnit_CN AND CuttingUnit.Code = ?;", (object)unit);
            }
            return dal.From<PlotDO>()
                .Join("CuttingUnit", "USING (CuttingUnit_CN)")
                .Join("Stratum", "USING (Stratum_CN)")
                .Where("CuttingUnit.Code = ? AND Stratum.Code = ?")
                .Read(unit, stratum).ToList();

            //.Read<PlotDO>("JOIN CuttingUnit JOIN Stratum WHERE Plot.CuttingUnit_CN = CuttingUnit.CuttingUnit_CN AND CuttingUnit.Code = ? AND Plot.Stratum_CN = Stratum.Stratum_CN AND Stratum.Code = ?;", (object)unit, stratum);
        }
        public int DeleteStratumStats(DatastoreRedux dal, long? StratumStats_CN)
        {
            //Delete sample group stats for stratum
            var allSGStatsInStratumStats = dal.From<SampleGroupStatsDO>()
                 .Where("StratumStats_CN = ?")
                 .Read(StratumStats_CN).ToList();

               foreach (SampleGroupStatsDO SgStats in allSGStatsInStratumStats)
               {
              SgStats.Delete();
               }

               Delete();

               return (0);
        }
        public int DeleteSampleGroup(DatastoreRedux dal, long? SampleGroup_CN)
        {
            // check tree table for data
            if (dal.GetRowCount("Tree", "WHERE SampleGroup_CN = ?", SampleGroup_CN) > 0) return (-1);
            // Check Count table for each sample group
            if (dal.GetRowCount("CountTree", "WHERE SampleGroup_CN = ? AND TreeCount > 0", SampleGroup_CN) > 0) return (-1);

            //Delete Count Records for stratum
            var allCountInSg = dal.From<CountTreeDO>()
                    .Where("SampleGroup_CN = ?")
                    .Read(SampleGroup_CN).ToList();

            foreach (CountTreeDO Cnt in allCountInSg)
            { Cnt.Delete(); }

            Delete();

            return (0);
        }