public void calc100(StratumStatsDO curStrStats, SampleGroupStatsDO curSgStats, bool useDefault, float treePerAcre, float volumePerAcre)
        {
            double sgCV = 100;
             double sgError = 0;

             calcStats cStat = new calcStats();
             if (!useDefault)
             {
            sgCV = cStat.getCV(treeVolumes, treeVolumes2, treeCount);
            curSgStats.CV_Def = 0;
            curSgStats.CV2_Def = 0;
             }
             else
             {
            curSgStats.CV_Def = 1;
            curSgStats.CV2_Def = 1;
             }
             curSgStats.TreesPerAcre = treePerAcre;
             curSgStats.VolumePerAcre = volumePerAcre;
             curSgStats.TreesPerPlot = 0;
             curSgStats.AverageHeight = 0;
             curSgStats.ReconPlots = plotCount;
             curSgStats.ReconTrees = treeCount;

             //copy calculated stuff
             curSgStats.CV1 = (float)sgCV;
             curSgStats.SampleSize1 = (long)(treePerAcre * totalAcres);
             curSgStats.TPA_Def = (long)(treePerAcre * totalAcres);
             curSgStats.VPA_Def = (long)(volumePerAcre * totalAcres);
             curSgStats.SgError = (float)sgError;

             curSgStats.Save();
        }
        public int getPopulations(StratumDO currentStratum)
        {
            // for each stratum
             stage = statClass.isTwoStage(currentStratum.Method);
             strStats = new StratumStatsDO(cdDAL);
             strStats.Stratum = currentStratum;
             strStats.Code = currentStratum.Code;
             strStats.Description = currentStratum.Description;
             strStats.SgSet = 1;
             strStats.SgSetDescription = "";

             float totalAcres = 0;
             currentStratum.CuttingUnits.Populate();

             foreach (CuttingUnitDO cu in currentStratum.CuttingUnits)
             {
            float acres = cu.Area;
            totalAcres += acres;
             }

             strStats.TotalAcres = totalAcres;
             strStats.Method = currentStratum.Method;
             strStats.BasalAreaFactor = currentStratum.BasalAreaFactor;
             strStats.FixedPlotSize = currentStratum.FixedPlotSize;
             strStats.Used = 1;
             strStats.Save();

             if (getSampleGroupStats(currentStratum, strStats, totalAcres) < 0)
            return(-1);

             getStratumStats(strStats);
             // create stratum sets;
             // create sample group sets
             // calculate stats
             return (0);
        }
        //---------------------------------------------------------------------------------------------------------
        private int getSampleGroupStats(StratumDO currentStratum, StratumStatsDO currentStratumStats, float totalAcres)
        {
            int n1, n2, measTrees, sumKpi, talliedTrees, freq, kz, insTrees;
             double st1x, st1x2, st2x, st2x2, cv1, cv2, sampErr, sumNetVol;
             float treesPerAcre;
             double comberr2 = 0;
             double totalVolume = 0;
             // for each sample group
             sampleGroups = new List<SampleGroupDO>(cdDAL.Read<SampleGroupDO>("SampleGroup", "Where Stratum_CN = ?", currentStratum.Stratum_CN));

             foreach (SampleGroupDO sg in sampleGroups)
             {
            // create samplegroupstats
            currentSgStats = new SampleGroupStatsDO(cdDAL);
            //set foriegn key
            currentSgStats.StratumStats = currentStratumStats;
            currentSgStats.SgSet = 1;
            currentSgStats.Code = sg.Code;
            currentSgStats.CutLeave = sg.CutLeave;
            currentSgStats.UOM = sg.UOM;
            currentSgStats.PrimaryProduct = sg.PrimaryProduct;
            currentSgStats.SecondaryProduct = sg.SecondaryProduct;
            currentSgStats.DefaultLiveDead = sg.DefaultLiveDead;
            currentSgStats.Description = sg.Description;
            // get POP data
            selectedPOP = cdDAL.ReadSingleRow<POPDO>("POP", "WHERE Stratum = ? AND SampleGroup = ?", currentStratum.Code, sg.Code);

            // calculate statistics (based on method)
            if (selectedPOP == null)
            {
               MessageBox.Show("Cruise Not Processed. Please Process Cruise Before Continuing.", "Warning");
               return(-1);
            }
            n1 = Convert.ToInt32(selectedPOP.StageOneSamples);
            n2 = Convert.ToInt32(selectedPOP.StageTwoSamples);
            measTrees = Convert.ToInt32(selectedPOP.MeasuredTrees);
            talliedTrees = Convert.ToInt32(selectedPOP.TalliedTrees);
            sumKpi = Convert.ToInt32(selectedPOP.SumKPI);
            st1x = selectedPOP.Stg1NetXPP;
            st1x2 = selectedPOP.Stg1NetXsqrdPP;
            st2x = selectedPOP.Stg2NetXPP;
            st2x2 = selectedPOP.Stg2NetXsqrdPP;
            // trees per plot
            // find CVs
            cv1 = statClass.getCV(st1x, st1x2, n1);
            if (stage == 12 || stage == 22)
               cv2 = statClass.getCV(st2x, st2x2, n2);
            else
               cv2 = 0;
            // find errors stage 11=tree,single 12=tree,2 stage 21=plot,single 22=plot,2 stage
            if (stage == 11 || stage == 21)
               sampErr = statClass.getSampleError(cv1, n1, 0);
            else if (stage == 12 || stage == 22)
               sampErr = statClass.getTwoStageError(cv1, cv2, n1, n2);
            else
               sampErr = 0;
            currentSgStats.CV1 = Convert.ToSingle(cv1);
            currentSgStats.CV2 = Convert.ToSingle(cv2);
            currentSgStats.SampleSize1 = n1;
            currentSgStats.SampleSize2 = n2;
            if (stage == 11 || stage == 10)
            {
               currentSgStats.ReconTrees = n1;
               currentSgStats.ReconPlots = 0;
            }
            else if (stage == 12)
            {
               currentSgStats.ReconPlots = n1;
               currentSgStats.ReconTrees = n2;
            }
            else if (stage == 21 || stage == 22)
            {
               currentSgStats.ReconTrees = measTrees;
               currentSgStats.ReconPlots = n1;
            }
            // calculate frequency

            currentSgStats.SgError = Convert.ToSingle(sampErr);

            // get LCD data
            selectedLCD = cdDAL.Read<LCDDO>("LCD", "WHERE Stratum = ? AND SampleGroup = ?", currentStratum.Code, sg.Code);
            sumExpFac = 0;
            sumNetVol = 0;
            //foreach (SampleGroupDO sg in Owner.histSampleGroup)
            foreach (LCDDO lcd in selectedLCD)
            {
               // sum volume
               double expFac = lcd.SumExpanFactor;
               sumExpFac += expFac;
               // sum trees
               double netVol = lcd.SumNCUFT;
               sumNetVol += netVol;
            }
            comberr2 += (sampErr * sumNetVol) * (sampErr * sumNetVol);
            totalVolume += sumNetVol;
            // find volume/acre and trees/acre
            if (stage < 20)
            {
               treesPerAcre = Convert.ToSingle(Math.Round((sumExpFac / totalAcres), 2));
               currentSgStats.TreesPerAcre = treesPerAcre;
               currentSgStats.VolumePerAcre = Convert.ToSingle(Math.Round((sumNetVol / totalAcres), 2));
            }
            else
            {
               treesPerAcre = Convert.ToSingle(Math.Round((sumExpFac), 2));
               currentSgStats.TreesPerAcre = treesPerAcre;
               currentSgStats.VolumePerAcre = Convert.ToSingle(Math.Round((sumNetVol), 2));
               if (stage == 21)
                  currentSgStats.TreesPerPlot = Convert.ToSingle(Math.Round((Convert.ToSingle((float)measTrees / (float)n1)), 1));
               else
                  currentSgStats.TreesPerPlot = Convert.ToSingle(Math.Round((Convert.ToSingle((float)talliedTrees / (float)n1)), 1));
            }
            currentSgStats.TPA_Def = (long)(treesPerAcre * totalAcres);
            // find frequency/KZ/BigBAF values
            if ((stage == 11 || stage == 12 || stage == 22) && measTrees > 0)
            {
               freq = Convert.ToInt32((talliedTrees / measTrees));
               kz = Convert.ToInt32((sumKpi / measTrees));

               if (currentStratum.Method == "S3P")
               {
                  currentSgStats.SamplingFrequency = Convert.ToInt32((talliedTrees / n1));
                  currentSgStats.KZ = kz;
               }
               else
               {
                  currentSgStats.SamplingFrequency = freq;
                  currentSgStats.KZ = kz;
               }
            }
            // find insurance trees
            if (stage == 11 || stage == 12)
               insTrees = getInsuranceTrees(sg);
            else
               insTrees = 0;
            currentSgStats.InsuranceFrequency = insTrees;
            // save samplegroupstats row
            currentSgStats.Save();
            // loop through TDV information
            sg.TreeDefaultValues.Populate();
            foreach (TreeDefaultValueDO tdv in sg.TreeDefaultValues)
            {
                currentSgStats.TreeDefaultValueStats.Add(tdv);
            }

            currentSgStats.Save();
            currentSgStats.TreeDefaultValueStats.Save();

             }
             return (0);
        }
        //*************************************************************************
        public void getStratumStats(StratumStatsDO thisStrStats)
        {
            List<SampleGroupStatsDO> mySgStats;
             float totalVolumeAcre, totalVolume, wtCV1, wtCv2, volumeAcre;
             float cv1, cv2, wtErr, sgErr, treesAcre;
             long sampleSize1, sampleSize2;
             string _UOM = "";
             //loop through SampleGroupStats

             mySgStats = new List<SampleGroupStatsDO>(cdDAL.Read<SampleGroupStatsDO>("SampleGroupStats", "Where StratumStats_CN = ?", thisStrStats.StratumStats_CN));
             // loop through sample groups
             //totalVolumeAcre = getTotals(mySgStats);
             totalVolumeAcre = mySgStats.Sum(P => P.VolumePerAcre);
             totalVolume = totalVolumeAcre * thisStrStats.TotalAcres;
             treesAcre = 0;
             sampleSize1 = 0;
             sampleSize2 = 0;
             wtCV1 = 0;
             wtCv2 = 0;
             wtErr = 0;
             foreach (SampleGroupStatsDO thisSgStats in mySgStats)
             {
            //sum volumes, trees/acre, sample sizes
            treesAcre += thisSgStats.TreesPerAcre;
            if(stage > 20)
               sampleSize1 = thisSgStats.SampleSize1;
            else
               sampleSize1 += thisSgStats.SampleSize1;
            sampleSize2 += thisSgStats.SampleSize2;
            volumeAcre = thisSgStats.VolumePerAcre;
            cv1 = thisSgStats.CV1;
            cv2 = thisSgStats.CV2;
            sgErr = thisSgStats.SgError;
            //calculate weighted CVs
            if (totalVolumeAcre > 0)
            {
               wtCV1 += cv1 * (volumeAcre / totalVolumeAcre);
               wtCv2 += cv2 * (volumeAcre / totalVolumeAcre);
            }

            wtErr += (float)Math.Pow((sgErr * (volumeAcre * thisStrStats.TotalAcres)), 2);
            _UOM = thisSgStats.UOM;
             }
             //save calculated values
             if (totalVolume > 0)
            thisStrStats.StrError = (float)Math.Sqrt(wtErr) / totalVolume;
             else
            thisStrStats.StrError = 0;
             thisStrStats.SampleSize1 = sampleSize1;
             thisStrStats.SampleSize2 = sampleSize2;
             thisStrStats.WeightedCV1 = wtCV1;
             thisStrStats.WeightedCV2 = wtCv2;
             thisStrStats.TreesPerAcre = treesAcre;
             thisStrStats.VolumePerAcre = totalVolumeAcre;
             //Uom Check
             if(_UOM == "01")
            thisStrStats.TotalVolume = (float)(totalVolume / 1000.0);
             else
            thisStrStats.TotalVolume = (float)(totalVolume / 100.0);
             if (thisStrStats.Method == "FIX" || thisStrStats.Method == "FCM" || thisStrStats.Method == "F3P" || thisStrStats.Method == "PNT" || thisStrStats.Method == "PCM" || thisStrStats.Method == "P3P" || thisStrStats.Method == "3PPNT")
             {
            if (sampleSize1 > 0)
               thisStrStats.PlotSpacing = (int)Math.Floor(Math.Sqrt((thisStrStats.TotalAcres * 43560) / sampleSize1));
             }
             else
             {
            if (thisStrStats.TreesPerAcre > 0)
               thisStrStats.PlotSpacing = (int)Math.Floor(Math.Sqrt((43560) / thisStrStats.TreesPerAcre));
             }

             thisStrStats.Save();
        }
        public void GoToHistPage()
        {
            // If from UnitPage - get new currentStratumStats
             currentStratumStats = (cdDAL.ReadSingleRow<StratumStatsDO>("StratumStats", "WHERE Stratum_CN = ? AND SgSet = 1", currentStratum.Stratum_CN));

             if (currentStratumStats != null)
             {
            // data already exists for stratum, delete stratum and continue?
            MessageBox.Show("Stratum data already exists for this stratum","Information");
            return;

             }

             currentStratumStats = new StratumStatsDO(cdDAL);
             currentStratumStats.Stratum = currentStratum;
             currentStratumStats.Code = currentStratum.Code;
             currentStratumStats.Description = currentStratum.Description;
             currentStratumStats.SgSet = 1;
             currentStratumStats.SgSetDescription = "";

             float totalAcres = 0;
             foreach (CuttingUnitDO cu in currentStratum.CuttingUnits)
             {
            float acres = cu.Area;
            totalAcres += acres;
             }
             currentStratumStats.TotalAcres = totalAcres;
            //         Owner.currentStratumStats.Save();

             if (openFileDialog1.ShowDialog() == DialogResult.OK)
             {
            histFile = openFileDialog1.FileName;
            //set title bar with file name
            histPage.textBoxFile.Text = openFileDialog1.SafeFileName;
            //open new cruise DAL
            if (histFile.Length > 0)
            {
               try
               {
                  hDAL = new DAL(histFile);
               }
               catch (System.IO.IOException ie)
               {
                  Logger.Log.E(ie);
               }
               catch (System.Exception ie)
               {
                  Logger.Log.E(ie);
               }
            }
            else
            {
               return;
            }

            Sale = new SaleDO(hDAL.ReadSingleRow<SaleDO>("Sale", null, null));
            string sUOM = Sale.DefaultUOM;
            if (sUOM != UOM)
            {
               MessageBox.Show("Cruise does not have same UOM.\nCannot import data.", "Warning");
               return;
            }

            //set binding list for stratum
            histStratum = new BindingList<StratumDO>(hDAL.Read<StratumDO>("Stratum", null, null));
            histPage.bindingSourceStratum.DataSource = histStratum;

            pageHost2.Display(histPage);
             }
        }
        public void getTreeFieldSetup(DAL cDAL, DAL fsDAL, StratumStatsDO myStStats)
        {
            //select from TreeFieldSetupDefault where method = stratum.method
             List<TreeFieldSetupDefaultDO> treeFieldDefaults = new List<TreeFieldSetupDefaultDO>(cDAL.Read < TreeFieldSetupDefaultDO >("TreeFieldSetupDefault", "WHERE Method = ? ORDER BY FieldOrder", myStStats.Method));
             foreach (TreeFieldSetupDefaultDO tfd in treeFieldDefaults)
             {
            TreeFieldSetupDO tfs = new TreeFieldSetupDO();
            tfs.Stratum_CN = thisStrCN;
            tfs.Field = tfd.Field;
            tfs.FieldOrder = tfd.FieldOrder;
            tfs.ColumnType = tfd.ColumnType;
            tfs.Heading = tfd.Heading;
            tfs.Width = tfd.Width;
            tfs.Format = tfd.Format;
            tfs.Behavior = tfd.Behavior;

            treeFields.Add(tfs);

             }
             fsDAL.Save(treeFields);
        }
        public int getReconData(StratumStatsDO curStrStats, SampleGroupStatsDO curSgStats, DAL rDAL, DAL fsDAL, List<PlotDO> myPlots, List<TreeDO> myTree, List<LogDO> myLogs, long? sampleGroupCN, bool first, int measHit)
        {
            TreeDO fsTree;
             LogDO fsLog;
             long? plotCN = 0;
             var myTreeList = myTree;
             var myLogList = myLogs;
             int treeCnt = 1;

             curStrStats.Stratum.CuttingUnits.Populate();
             curSgStats.TreeDefaultValueStats.Populate();
             // loop through design units
             foreach (CuttingUnitDO curUnit in curStrStats.Stratum.CuttingUnits)
             {
            // get number of plots for stratum and cutting unit
            var myPlotList = (from plt in myPlots
                              where plt.CuttingUnit_CN == curUnit.CuttingUnit_CN
                              select plt).ToList();
            // loop through plots
            foreach (PlotDO curPlot in myPlotList)
            {
               // if first time for stratum, save plots
               plotCN = savePlots(curPlot, curStrStats.Stratum_CN, first);

               foreach (TreeDefaultValueDO curTdv in curSgStats.TreeDefaultValueStats)
               {
                  if (curSgStats.MinDbh > 0 && curSgStats.MaxDbh > 0)
                  {
                     double maxDbh = curSgStats.MaxDbh + 0.0499;
                     double minDbh = curSgStats.MinDbh - 0.0500;
                     myTreeList = (from tcv in myTree
                                       where tcv.SampleGroup.PrimaryProduct == curSgStats.PrimaryProduct
                                       && tcv.Plot_CN == curPlot.Plot_CN
                                       && tcv.Species == curTdv.Species
                                       && tcv.LiveDead == curTdv.LiveDead
                                       && tcv.DBH >= minDbh
                                       && tcv.DBH <= maxDbh
                                       select tcv).ToList();
                  }
                  else
                  {
                     myTreeList = (from tcv in myTree
                                       where tcv.SampleGroup.PrimaryProduct == curSgStats.PrimaryProduct
                                       && tcv.Plot_CN == curPlot.Plot_CN
                                       && tcv.Species == curTdv.Species
                                       && tcv.LiveDead == curTdv.LiveDead
                                       select tcv).ToList();
                  }

                  foreach (TreeDO rTree in myTreeList)
                  {
                     fsTree = new TreeDO(fsDAL);
                     fsTree.Stratum_CN = thisStrCN;
                     fsTree.TreeDefaultValue_CN = curTdv.TreeDefaultValue_CN;
                     fsTree.SampleGroup_CN = sampleGroupCN;
                     fsTree.Plot_CN = plotCN;
                     fsTree.CuttingUnit_CN = curUnit.CuttingUnit_CN;
                     fsTree.TreeNumber = rTree.TreeNumber;
                     fsTree.Species = rTree.Species;
                     if (curStrStats.Method == "PCM" || curStrStats.Method == "FCM")
                     {
                        if (radioButton1.Checked)
                        {
                           // use frequency
                           // check hit
                           if (treeCnt == measHit)
                           {
                              fsTree.CountOrMeasure = "M";
                              measHit += (int)curSgStats.SamplingFrequency;
                           }
                           else
                              fsTree.CountOrMeasure = "C";

                        }
                        else if (radioButton2.Checked)
                        {
                           fsTree.CountOrMeasure = "C";
                        }
                        else
                           fsTree.CountOrMeasure = "M";
                     }
                     else
                        fsTree.CountOrMeasure = rTree.CountOrMeasure;
                     treeCnt++;
                     fsTree.TreeCount = 1;
                     fsTree.SeenDefectPrimary = rTree.SeenDefectPrimary;
                     fsTree.SeenDefectSecondary = rTree.SeenDefectSecondary;
                     fsTree.RecoverablePrimary = rTree.RecoverablePrimary;
                     fsTree.Initials = rTree.Initials;
                     fsTree.LiveDead = rTree.LiveDead;
                     fsTree.Grade = rTree.Grade;
                     fsTree.HeightToFirstLiveLimb = rTree.HeightToFirstLiveLimb;
                     fsTree.DBH = rTree.DBH;
                     fsTree.DRC = rTree.DRC;
                     fsTree.TotalHeight = rTree.TotalHeight;
                     fsTree.MerchHeightPrimary = rTree.MerchHeightPrimary;
                     fsTree.MerchHeightSecondary = rTree.MerchHeightSecondary;
                     fsTree.FormClass = rTree.FormClass;
                     fsTree.UpperStemHeight = rTree.UpperStemHeight;
                     fsTree.TopDIBPrimary = rTree.TopDIBPrimary;
                     fsTree.TopDIBSecondary = rTree.TopDIBSecondary;
                     //fsTree.CreatedBy = rTree.CreatedBy;
                     //fsTree.CreatedDate = rTree.CreatedDate;

                     fsTree.Save();
                     // save logs
                     myLogList = (from lcv in myLogs
                                  where lcv.Tree_CN == rTree.Tree_CN
                                  select lcv).ToList();

                     foreach (LogDO rLog in myLogList)
                     {
                        fsLog = new LogDO(fsDAL);
                        fsLog.Tree_CN = rLog.Tree_CN;
                        fsLog.LogNumber = rLog.LogNumber;
                        fsLog.Grade = rLog.Grade;
                        fsLog.SeenDefect = rLog.SeenDefect;
                        fsLog.PercentRecoverable = rLog.PercentRecoverable;
                        fsLog.Length = rLog.Length;
                        fsLog.ExportGrade = rLog.ExportGrade;
                        fsLog.SmallEndDiameter = rLog.SmallEndDiameter;
                        fsLog.LargeEndDiameter = rLog.LargeEndDiameter;
                        fsLog.GrossBoardFoot = rLog.GrossBoardFoot;
                        fsLog.NetBoardFoot = rLog.NetBoardFoot;
                        fsLog.GrossCubicFoot = rLog.GrossCubicFoot;
                        fsLog.NetCubicFoot = rLog.NetCubicFoot;
                        fsLog.DIBClass = rLog.DIBClass;
                        fsLog.BarkThickness = rLog.BarkThickness;
                        fsLog.Save();
                    }
                  }
               }
            }
             }
             return (0);
        }
        public void calculateStats(StratumStatsDO curStrStats, SampleGroupStatsDO curSgStats, bool useDefault, float treePerAcre, float volumePerAcre, float treePerPlot, String method)
        {
            double sgCV = 100;
             double sgCV2 = 0;
             double sgError = 40;
             int n = 0;
             int n2 = 0;
             int KZ = 0;
             int Freq = 0;

             calcStats cStat = new calcStats();
             if (!useDefault)
             {
            if (method == "FIX")
            {
               sgCV = cStat.getPntCV(plotVolume, plotVolume2, pntFac, plotCount);
               sgError = cStat.getSampleError(sgCV, plotCount, 0);
               n = plotCount;
               n2 = treePlot;
            }
            else if (method == "PNT")
            {
               sgCV = cStat.getPntCV(vBarSum, vBarPlot2, pntFac, plotCount);
               sgError = cStat.getSampleError(sgCV, plotCount, 0);
               n = plotCount;
               n2 = treePlot;
            }
            else if (method == "F3P")
            {
               sgCV = cStat.getPntCV(plotVolume, plotVolume2, pntFac, plotCount);
               sgCV2 = 30;
               sgError = cStat.getTwoStageError(sgCV, sgCV2, plotCount, treePlot);
               n = plotCount;
               n2 = treePlot;
               KZ = 1;
            }
            else if (method == "P3P" || method == "3PPNT")
            {
               sgCV = cStat.getPntCV(vBarSum, vBarPlot2, pntFac, plotCount);
               sgCV2 = 30;
               sgError = cStat.getTwoStageError(sgCV, sgCV2, plotCount, treePlot);
               n = plotCount;
               n2 = treePlot;
               if (method == "3PPNT") n2 = plotCount;
               KZ = 1;
            }
            else if (method == "FCM")
            {
               sgCV = cStat.getCV(treePlot, treePlot2, plotCount);
               sgCV2 = cStat.getCV(treeVolumes, treeVolumes2, treePlot);
               sgError = cStat.getTwoStageError(sgCV, sgCV2, plotCount, treePlot);
               n = plotCount;
               n2 = treePlot;
               Freq = 1;
            }
            else if (method == "PCM")
            {
               sgCV = cStat.getCV(treePlot, treePlot2, plotCount);
               sgCV2 = cStat.getCV(vBarSum, vBarSum2, treePlot);
               sgError = cStat.getTwoStageError(sgCV, sgCV2, plotCount, treePlot);
               n = plotCount;
               n2 = treePlot;
               Freq = 1;
            }
            else if (method == "STR")
            {
               sgCV = cStat.getCV(treeVolumes, treeVolumes2, treeCount);
               sgError = cStat.getSampleError(sgCV, treeCount, 0);
               n = treePlot;
               if (treePlot > 0)
                  Freq = (int)Math.Floor((treePerAcre * totalAcres) / treeCount);
               else
                  Freq = 0;
            }
            else if (method == "3P")
            {
               sgCV = 35;
               sgError = cStat.getSampleError(sgCV, treeCount, 0);
               n = treePlot;
               if (treeVolumes > 0)
                  KZ = (int)Math.Floor((volumePerAcre * totalAcres) / treeVolumes);
               else
                  KZ = 0;
            }
            else if (method == "S3P")
            {
               sgCV = cStat.getCV(treeVolumes, treeVolumes2, treeCount);
               sgCV2 = 35;
               sgError = cStat.getTwoStageError(sgCV, sgCV2, treeCount, treeCount);
               if (treeVolumes > 0)
                  KZ = (int)Math.Floor((volumePerAcre * totalAcres) / treeVolumes);
               else
                  KZ = 0;
               Freq = 1;
            }
             }
             else
             {
            if (method == "FCM" || method == "PCM")
            {
               sgCV2 = 100;
               cStat.getTwoStageSampleSize(sgCV, sgCV2, sgError);
               n = (int)cStat.sampleSize1;
               n2 = (int)cStat.sampleSize2;
            }
            else if (method == "F3P" || method == "P3P" || method == "S3P" || method == "3PPNT")
            {
               sgCV2 = 35;
               cStat.getTwoStageSampleSize(sgCV, sgCV2, sgError);
               n = (int)cStat.sampleSize1;
               n2 = (int)cStat.sampleSize2;
            }
            else
            {
               n = cStat.getSampleSize(sgError, sgCV);
            }
             }

             // Find the strataStats_CN
             long? strStatsCN = GetStratumStatsCN(curStrStats, method);
             // Create SampleGroupStats record with StratumStats CN and save stats
             SampleGroupStatsDO newSgStats = new SampleGroupStatsDO(cdDAL);
             //copy standard info
             newSgStats.StratumStats_CN = strStatsCN;
             newSgStats.Code = curSgStats.Code;
             newSgStats.Description = curSgStats.Description;
             newSgStats.SgSet = curSgStats.SgSet;
             newSgStats.CutLeave = curSgStats.CutLeave;
             newSgStats.UOM = curSgStats.UOM;
             newSgStats.PrimaryProduct = curSgStats.PrimaryProduct;
             newSgStats.SecondaryProduct = curSgStats.SecondaryProduct;
             newSgStats.DefaultLiveDead = curSgStats.DefaultLiveDead;
             newSgStats.MinDbh = curSgStats.MinDbh;
             newSgStats.MaxDbh = curSgStats.MaxDbh;
             // general stuff
             newSgStats.TreesPerAcre = treePerAcre;
             newSgStats.VolumePerAcre = volumePerAcre;
             newSgStats.TreesPerPlot = treePerPlot;
             newSgStats.TPA_Def = (long)(treePerAcre * totalAcres);
             newSgStats.VPA_Def = (long)(volumePerAcre * totalAcres);
             if (treeCount > 0)
            newSgStats.AverageHeight = (float)(treeHeights / treeCount);
             else
            newSgStats.AverageHeight = 0;
             newSgStats.KZ = KZ;
             newSgStats.BigBAF = 0;
             newSgStats.BigFIX = 0;
             newSgStats.SamplingFrequency = Freq;
             newSgStats.InsuranceFrequency = 0;
             //copy calculated stuff
             newSgStats.CV1 = (float)sgCV;
             newSgStats.CV2 = (float)sgCV2;
             newSgStats.SampleSize1 = n;
             newSgStats.SampleSize2 = n2;
             newSgStats.SgError = (float)sgError;
             if (useDefault)
             {
            newSgStats.CV_Def = 1;
            newSgStats.CV2_Def = 1;
             }
             else
             {
            newSgStats.CV_Def = 0;
            newSgStats.CV2_Def = 0;
             }
             newSgStats.ReconPlots = plotCount;
             newSgStats.ReconTrees = treeCount;

             //selectSgStats.Add(newSgStats);
             newSgStats.Save();
             //long? sgcn = newSgStats.SampleGroupStats_CN;
             curSgStats.TreeDefaultValueStats.Populate();
             foreach (TreeDefaultValueDO myTDV in curSgStats.TreeDefaultValueStats)
             {
            SampleGroupStatsTreeDefaultValueDO mySgTDV = new SampleGroupStatsTreeDefaultValueDO(cdDAL);
            mySgTDV.TreeDefaultValue_CN = myTDV.TreeDefaultValue_CN;
            mySgTDV.SampleGroupStats = newSgStats;
            mySgTDV.Save();
             }
        }
Esempio n. 9
0
		public StratumStatsDO(StratumStatsDO obj) : this()
		{
		    SetValues(obj);
		}
        //********************                                                                      getSgReconData
        public int getSgReconData(StratumStatsDO curStrStats, SampleGroupStatsDO curSgStats, string method)
        {
            CuttingUnitDO rUnit;
             SampleGroupDO rSampleGroup;
             long? myStratumCN = 0;
             //long?[] stratumArray = new long?[10];

             //get search variables
             if (!reconExists)
            return (1);
             double vBar;
             int unitCnt = 0;
             treeHeights = 0;
             plotCount = 0;
             plotVolume = 0;
             plotVolume2 = 0;
             treePlot = 0;
             treePlot2 = 0;
             vExpFac = 0;
             sumExpFac = 0;
             treeCount = 0;
             treeVolumes = 0;
             treeVolumes2 = 0;
             vBarSum = 0;
             vBarSum2 = 0;
             vBarPlot2 = 0;
             //         currentTreeList.Clear();
             curSgStats.TreeDefaultValueStats.Populate();
             // loop through design units
             foreach (CuttingUnitDO curUnit in curStrStats.Stratum.CuttingUnits)
             {
            rUnit = rDAL.ReadSingleRow<CuttingUnitDO>("CuttingUnit", "Where Code = ?", curUnit.Code);
            if (rUnit != null)
            {
               unitCnt++;
               rUnit.Strata.Populate();
               int cnt = 0;
               foreach (StratumDO myStratum in rUnit.Strata)
               {
                  if (myStratum.Method == method)
                  {
                     // check sample group product code
                     rSampleGroup = rDAL.ReadSingleRow<SampleGroupDO>("SampleGroup", "Where Stratum_CN = ? AND PrimaryProduct = ?", myStratum.Stratum_CN, curSgStats.PrimaryProduct);
                     if (rSampleGroup != null)
                     {
                        myStratumCN = myStratum.Stratum_CN;
                        if (method == "FIX")
                           curSgPlotSize = myStratum.FixedPlotSize;
                        else if (method == "PNT")
                           curSgPlotSize = myStratum.BasalAreaFactor;
                        cnt++;
                     }
                  }
               }
               if (cnt == 0)
               {
                  return (1);
               }
               else if (cnt > 1)
               {
                  // loop through stratumArray

                  // popup to select correct stratum
               }
               //            else
               //              myStratumCN = stratumArray[0];

               // get number of plots for stratum and cutting unit
               var myPlotList = (from plt in myPlots
                                 where plt.CuttingUnit_CN == rUnit.CuttingUnit_CN
                                 && plt.Stratum_CN == myStratumCN
                                 select plt).ToList();
               //List<PlotDO> myPlots = new List<PlotDO>(rDAL.Read<PlotDO>("Plot", "WHERE Plot.CuttingUnit_CN = ? AND Plot.Stratum_CN = ?", rUnit.CuttingUnit_CN, myStratumCN));
               plotCount += myPlotList.Count();
               // loop through plots
               foreach (PlotDO curPlot in myPlotList)
               {
                  pltVol = 0;
                  vBarPlot = 0;
                  int plotTreeCount = 0;
                  vExpFac = 0;

                  foreach (TreeDefaultValueDO curTdv in curSgStats.TreeDefaultValueStats)
                  {
                     double maxDbh = 200;
                     double minDbh = 0;
                     if (curSgStats.MinDbh > 0 && curSgStats.MaxDbh > 0)
                     {
                        maxDbh = curSgStats.MaxDbh + 0.0499;
                        minDbh = curSgStats.MinDbh - 0.0500;
                     }
                        var myTreeList = (from tcv in rTreeCalcJoin
                                      where tcv.Tree.SampleGroup.PrimaryProduct == curSgStats.PrimaryProduct
                                      && tcv.Tree.Plot_CN == curPlot.Plot_CN
                                      && tcv.Tree.Species == curTdv.Species
                                      && tcv.Tree.LiveDead == curTdv.LiveDead
                                      && tcv.Tree.DBH >= minDbh
                                      && tcv.Tree.DBH <= maxDbh
                                      select tcv).ToList();

                     // load Unit, Plot, Tree, DBH, THT, Volume into list
                     //check MinDbh and MaxDbh
                     foreach (TreeCalculatedValuesDO myTree in myTreeList)
                     {
                        plotTreeCount++;
                        treeHeights += myTree.Tree.TotalHeight;

                        if (myTree.Tree.DBH > 0 && method == "PNT")
                        {
                           if (curSgStats.UOM == "01")
                              vBar = myTree.NetBDFTPP / (0.005454 * myTree.Tree.DBH * myTree.Tree.DBH);
                           else
                              vBar = myTree.NetCUFTPP / (0.005454 * myTree.Tree.DBH * myTree.Tree.DBH);

                           vBarSum += vBar;
                           vBarSum2 += (vBar * vBar);
                           vBarPlot += vBar;

                           vExpFac += curSgPlotSize / (0.005454 * myTree.Tree.DBH * myTree.Tree.DBH);
                        }

                        if (curSgStats.UOM == "01")
                        {
                           treeVolumes += myTree.NetBDFTPP;
                           treeVolumes2 += myTree.NetBDFTPP * myTree.NetBDFTPP;
                           pltVol += myTree.NetBDFTPP;
                        }
                        else
                        {
                           treeVolumes += myTree.NetCUFTPP;
                           treeVolumes2 += myTree.NetCUFTPP * myTree.NetCUFTPP;
                           pltVol += myTree.NetCUFTPP;
                        }
                     }
                  }
                  // save plot level information
                  treeCount += plotTreeCount;
                  treePlot += plotTreeCount;
                  treePlot2 += plotTreeCount * plotTreeCount;
                  plotVolume += pltVol;
                  plotVolume2 += pltVol * pltVol;
                  vBarPlot2 += vBarPlot * vBarPlot;
                  sumExpFac += vExpFac;

               }

               // !!!check for different fixed plot sizes across units!!!
               if (sgPlotSize == 0) sgPlotSize = curSgPlotSize;
               if (sgPlotSize != curSgPlotSize)
               {
                  // cannot calculate statistics
                  if (method == "FIX")
                  {
                     useDefaultFix = true;
                     useDefaultTree = true;
                  }
                  else if (method == "PNT")
                  {
                     useDefaultPnt = true;
                  }
               }
            }
             }
             if(unitCnt == 0) return (1);

             return (0);
        }
        public void getPopulations()
        {
            //MessageBox.Show("getPopulations");
             mySale = new SaleDO(cdDAL.ReadSingleRow<SaleDO>("Sale", null, null));
             if (reconExists)
             {
            // check for TreeDefaultValues - processed cruise
            //List<TreeCalculatedValuesDO> chkValues = new List<TreeCalculatedValuesDO>(rDAL.Read<TreeCalculatedValuesDO>("TreeCalculatedValues", null, null));
            rTreeCalcJoin = new List<TreeCalculatedValuesDO>(rDAL.Read<TreeCalculatedValuesDO>("TreeCalculatedValues", "JOIN Tree T JOIN SampleGroup G WHERE TreeCalculatedValues.Tree_CN = T.Tree_CN AND T.SampleGroup_CN = G.SampleGroup_CN", null));
            if (rTreeCalcJoin.Count() <= 0)
            {
               errFlag = 1;
               getDefaultData();
               // default values calc
               return;
            }
             }
             else
             {
            getDefaultData();
            return;
             }
             //get recon tree calculated list
             myPlots = new List<PlotDO>(rDAL.Read<PlotDO>("Plot", null, null));

             // get stratum definitions
             stratum = new List<StratumDO>(cdDAL.Read<StratumDO>("Stratum", null, null));

             // loop through stratum
             foreach (StratumDO curStr in stratum)
             {
            // check if Stratum needs to be re-calculated (if method = 100, then it needs to be recalculated)
            strStats = (cdDAL.ReadSingleRow<StratumStatsDO>("StratumStats", "WHERE Stratum_CN = ? AND SgSet = 1 AND Method = ?", curStr.Stratum_CN, "100"));
            if (curStr.Method == "100" && strStats.Used == 2)
            {
               curStr.CuttingUnits.Populate();
               // get total strata acres

               removePopulations(curStr.Stratum_CN);

               totalAcres = 0;
               foreach (CuttingUnitDO cu in curStr.CuttingUnits)
               {
                  float acres = cu.Area;
                  totalAcres += acres;
               }

               selectStratumStats = new List<StratumStatsDO>(cdDAL.Read<StratumStatsDO>("StratumStats", "WHERE Stratum_CN = ?", curStr.Stratum_CN));
               // loop by stratumstats for multiple SgSets
               foreach (StratumStatsDO curStrStats in selectStratumStats)
               {
                  useDefaultFix = false;
                  useDefaultTree = false;
                  useDefaultPnt = false;
                  curPlotFixSize = 0;
                  curPlotPntSize = 0;

                  // add methods to the StratumStats table (FIX,FCM,F3P,STR,3P,S3P,PNT,P3P,PCM,3PPNT)
                  //setupPopulations(curStrStats.Stratum_CN, curStrStats.Code, curStrStats.Description, curStrStats.SgSet, curStrStats.SgSetDescription, curStrStats.TotalAcres);

                  selectSgStats = new List<SampleGroupStatsDO>(cdDAL.Read<SampleGroupStatsDO>("SampleGroupStats", "Where StratumStats_CN = ?", curStrStats.StratumStats_CN));
                  // loop through sample groups
                  foreach (SampleGroupStatsDO curSgStats in selectSgStats)
                  {
                     //Get all statistics from FIX plots  **************
                     sgPlotSize = 0;
                     //find data from Recon file
                     int iReturn = getSgReconData(curStrStats, curSgStats, "FIX");

                     if (iReturn > 0)
                     {
                        useDefaultFix = true;
                        useDefaultTree = true;
                     }

                     if (curPlotFixSize == 0) curPlotFixSize = sgPlotSize;
                     // check plot sizes are not different across sample groups
                     if (curPlotFixSize != sgPlotSize)
                     {
                        // plot sizes are different across sample groups, cannot calculate Fix statistics
                        useDefaultFix = true;
                     }

                     // calc Fixed
                     getFixSgStats(curStrStats, curSgStats, useDefaultFix);

                     //Get all statistics from PNT plots  **************
                     curPlotFixSize = 0;
                     sgPlotSize = 0;
                     //find data from Recon file
                     iReturn = getSgReconData(curStrStats, curSgStats, "PNT");

                     if (iReturn > 0)
                     {
                        useDefaultPnt = true;
                     }

                     if (curPlotPntSize == 0) curPlotPntSize = sgPlotSize;
                     // check plot sizes are not different across sample groups
                     if (curPlotPntSize != sgPlotSize)
                     {
                        // plot sizes are different across sample groups, cannot calculate Fix statistics
                        useDefaultPnt = true;
                     }
                     getPntSgStats(curStrStats, curSgStats, useDefaultPnt);
                  }
               }
               //calculate StratumStats from the SampleGroupStats
               getStratumStats(curStr.Stratum_CN);

            }
            else
            {
              // selectStratumStats = new List<StratumStatsDO>(cdDAL.Read<StratumStatsDO>("StratumStats", "WHERE Stratum_CN = ?", curStr.Stratum_CN));
               // check for historical data
              // foreach (StratumStatsDO curStrStats in selectStratumStats)
              // {
                  // check for error equal to zero
              //    if (curStrStats.StrError == 0)
              //    {
              //       selectSgStats = new List<SampleGroupStatsDO>(cdDAL.Read<SampleGroupStatsDO>("SampleGroupStats", "Where StratumStats_CN = ?", curStrStats.StratumStats_CN));
                     // loop through sample groups
              //       foreach (SampleGroupStatsDO curSgStats in selectSgStats)
              //       {
              //          getDefaultStats(curStrStats, curSgStats);
              //       }
               //      getStratumStats(curStr.Stratum_CN);
               //   }
               //}
            }
             }
        }
 public void getPntSgStats(StratumStatsDO curStrStats, SampleGroupStatsDO curSgStats, bool useDefault)
 {
     //sgStats = new SampleGroupDO(cdDAL);
      float treePerAcre = 1;
      float volumePerAcre = 1;
      float treePerPlot = 1;
      if (!useDefault)
      {
     // calculate TPA
     treePerAcre = (float)(sumExpFac / plotCount);
     // calculate VPA
     pntFac = curSgPlotSize / plotCount;
     volumePerAcre = (float) (vBarSum * pntFac);
     // calculate TPP
     treePerPlot = (float)((float)treeCount / (float)plotCount);
     if (treePerPlot < .1 && treePerPlot > 0) treePerPlot = (float)(0.1);
      }
      // calculate statistics
      calculateStats(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre, treePerPlot, "PNT");
      calculateStats(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre, treePerPlot, "P3P");
      calculateStats(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre, treePerPlot, "PCM");
      calculateStats(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre, treePerPlot, "3PPNT");
 }
 //*********                                                                           setupPopulations
 public void getFixSgStats(StratumStatsDO curStrStats, SampleGroupStatsDO curSgStats, bool useDefault)
 {
     //sgStats = new SampleGroupDO(cdDAL);
      float treePerAcre = 1;
      float volumePerAcre = 1;
      float treePerPlot = 1;
      if (!useDefault)
      {
     // calculate Expansion Factor
     //expFac = curSgPlotSize / plotCount;
     // calculate TPA
       //          float xtreePerAcre = treeCount * expFac;
     pntFac = curSgPlotSize / plotCount;
     treePerAcre = (float) (pntFac * treeCount);
     // calculate VPA
     //            float xvolumePerAcre = plotVolume * expFac;
     volumePerAcre = (float)(plotVolume * pntFac);
     // calculate TPP
     //treePerPlot = (float) (treeCount / plotCount);
     treePerPlot = (float)((float)treeCount / (float)plotCount);
     if (treePerPlot < .1 && treePerPlot > 0) treePerPlot = (float)(0.1);
      }
      // calculate statistics
      calc100(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre);
      calculateStats(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre, treePerPlot, "FIX");
      calculateStats(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre, treePerPlot, "F3P");
      calculateStats(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre, treePerPlot, "FCM");
      calculateStats(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre, treePerPlot, "STR");
      calculateStats(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre, treePerPlot, "3P");
      calculateStats(curStrStats, curSgStats, useDefault, treePerAcre, volumePerAcre, treePerPlot, "S3P");
 }
        //*********                                                                           Get Default Data
        public void getDefaultData()
        {
            // get stratum definitions
             stratum = new List<StratumDO>(cdDAL.Read<StratumDO>("Stratum", null, null));

             // loop through stratum
             foreach (StratumDO curStr in stratum)
             {
            strStats = (cdDAL.ReadSingleRow<StratumStatsDO>("StratumStats", "WHERE Stratum_CN = ? AND SgSet = 1 AND Method = ?", curStr.Stratum_CN, "100"));
            if (curStr.Method == "100" && strStats.Used == 2)
            {
               curStr.CuttingUnits.Populate();
               // get total strata acres

               removePopulations(curStr.Stratum_CN);

               totalAcres = 0;
               foreach (CuttingUnitDO cu in curStr.CuttingUnits)
               {
                  float acres = cu.Area;
                  totalAcres += acres;
               }

               selectStratumStats = new List<StratumStatsDO>(cdDAL.Read<StratumStatsDO>("StratumStats", "WHERE Stratum_CN = ?", curStr.Stratum_CN));

               foreach (StratumStatsDO curStrStats in selectStratumStats)
               {
                  // check for error equal to zero
                  if (curStrStats.StrError == 0)
                  {
                     selectSgStats = new List<SampleGroupStatsDO>(cdDAL.Read<SampleGroupStatsDO>("SampleGroupStats", "Where StratumStats_CN = ?", curStrStats.StratumStats_CN));
                     // loop through sample groups
                     foreach (SampleGroupStatsDO curSgStats in selectSgStats)
                     {
                        getFixSgStats(curStrStats, curSgStats, true);
                        getPntSgStats(curStrStats, curSgStats, true);
                     }
                     getStratumStats(curStr.Stratum_CN);
                  }
               }
            }
             }
        }
 public long? GetStratumStatsCN(StratumStatsDO curStrStats, string method)
 {
     //find StratumStats_CN for population with Stratum_CN, Code, SgSet, method are the same
      StratumStatsDO thisStrStats = (cdDAL.ReadSingleRow<StratumStatsDO>("StratumStats", "WHERE Stratum_CN = ? AND SgSet = ? AND Method = ?", curStrStats.Stratum_CN, curStrStats.SgSet, method));
      //         currentStratumStats = (cdDAL.ReadSingleRow<StratumStatsDO>("StratumStats", "WHERE Stratum_CN = ? AND SgSet = 1", currentStratum.Stratum_CN));
      if (thisStrStats != null)
      {
     if(method == "FIX" || method == "FCM" || method == "F3P")
        thisStrStats.FixedPlotSize = curPlotFixSize;
     else if(method == "PNT" || method == "PCM" || method == "P3P" || method == "3PPNT")
        thisStrStats.BasalAreaFactor = curPlotPntSize;
     thisStrStats.TotalAcres = totalAcres;
     thisStrStats.Used = 0;
     thisStrStats.Save();
     return (thisStrStats.StratumStats_CN);
      }
      else
      {
     // add new record
     StratumStatsDO newStrStats = new StratumStatsDO(cdDAL);
     newStrStats.Stratum_CN = curStrStats.Stratum_CN;
     newStrStats.Code = curStrStats.Code;
     newStrStats.Description = curStrStats.Description;
     newStrStats.SgSet = curStrStats.SgSet;
     newStrStats.SgSetDescription = curStrStats.SgSetDescription;
     newStrStats.TotalAcres = totalAcres;
     newStrStats.Method = method;
     newStrStats.Used = 0;
     if (method == "FIX" || method == "FCM" || method == "F3P")
        newStrStats.FixedPlotSize = curPlotFixSize;
     else if (method == "PNT" || method == "PCM" || method == "P3P" || method == "3PPNT")
        newStrStats.BasalAreaFactor = curPlotPntSize;
     newStrStats.Save();
     // return StratumStats_CN
     return (newStrStats.StratumStats_CN);
      }
 }
        private void bindingSourceStratumStats_CurrentChanged(object sender, EventArgs e)
        {
            // display the SgStats
             if (currentStratumStats != null) currentStratumStats.Save();

             currentStratumStats = bindingSourceStratumStats.Current as StratumStatsDO;
             if (currentStratumStats != null)
             {
            cdSgStats = new BindingList<SampleGroupStatsDO>(cdDAL.Read<SampleGroupStatsDO>("SampleGroupStats", "Where StratumStats_CN = ?", currentStratumStats.StratumStats_CN));
            bindingSourceSgStats.DataSource = cdSgStats;
            meth = currentStratumStats.Method;
            totAcres = currentStratumStats.TotalAcres;

            setGridDisplay();
             }
        }
        public void getLogFieldSetup(DAL cDAL, DAL fsDAL, StratumStatsDO myStStats)
        {
            List<LogFieldSetupDefaultDO> logFieldDefaults = new List<LogFieldSetupDefaultDO>(cDAL.Read<LogFieldSetupDefaultDO>("LogFieldSetupDefault", null, null));
             foreach (LogFieldSetupDefaultDO lfd in logFieldDefaults)
             {
            LogFieldSetupDO lfs = new LogFieldSetupDO();
            lfs.Stratum_CN = thisStrCN;
            lfs.Field = lfd.Field;
            lfs.FieldOrder = lfd.FieldOrder;
            lfs.ColumnType = lfd.ColumnType;
            lfs.Heading = lfd.Heading;
            lfs.Width = lfd.Width;
            lfs.Format = lfd.Format;
            lfs.Behavior = lfd.Behavior;

            logFields.Add(lfs);
             }
             fsDAL.Save(logFields);
        }
Esempio n. 18
0
		public void SetValues(StratumStatsDO obj)
		{
			if(obj == null) { return; }
			Code = obj.Code;
			Description = obj.Description;
			Method = obj.Method;
			SgSet = obj.SgSet;
			SgSetDescription = obj.SgSetDescription;
			BasalAreaFactor = obj.BasalAreaFactor;
			FixedPlotSize = obj.FixedPlotSize;
			StrError = obj.StrError;
			SampleSize1 = obj.SampleSize1;
			SampleSize2 = obj.SampleSize2;
			WeightedCV1 = obj.WeightedCV1;
			WeightedCV2 = obj.WeightedCV2;
			TreesPerAcre = obj.TreesPerAcre;
			VolumePerAcre = obj.VolumePerAcre;
			TotalVolume = obj.TotalVolume;
			TotalAcres = obj.TotalAcres;
			PlotSpacing = obj.PlotSpacing;
			Used = obj.Used;
		}
        public int getReconData(StratumStatsDO curStrStats, SampleGroupStatsDO curSgStats, DAL rDAL, DAL fsDAL, List<PlotDO> myPlots, List<TreeDO> myTree, long? sampleGroupCN, bool first)
        {
            List<LogDO> rLog = new List<LogDO>();
             TreeDO fsTree;
             LogDO fsLog;
             long? plotCN = 0;
             var myTreeList = myTree;

             curStrStats.Stratum.CuttingUnits.Populate();
             curSgStats.TreeDefaultValueStats.Populate();
             // loop through design units
             foreach (CuttingUnitDO curUnit in curStrStats.Stratum.CuttingUnits)
             {
            // get number of plots for stratum and cutting unit
            var myPlotList = (from plt in myPlots
                              where plt.CuttingUnit_CN == curUnit.CuttingUnit_CN
                              select plt).ToList();
            // loop through plots
            foreach (PlotDO curPlot in myPlotList)
            {
               // if first time for stratum, save plots
               plotCN = savePlots(curPlot, curStrStats.Stratum_CN, first);

               foreach (TreeDefaultValueDO curTdv in curSgStats.TreeDefaultValueStats)
               {
                  if (curSgStats.MinDbh > 0 && curSgStats.MaxDbh > 0)
                  {
                     double maxDbh = curSgStats.MaxDbh + 0.0499;
                     double minDbh = curSgStats.MinDbh - 0.0500;
                     myTreeList = (from tcv in myTree
                                       where tcv.SampleGroup.PrimaryProduct == curSgStats.PrimaryProduct
                                       && tcv.Plot_CN == curPlot.Plot_CN
                                       && tcv.Species == curTdv.Species
                                       && tcv.LiveDead == curTdv.LiveDead
                                       && tcv.DBH >= minDbh
                                       && tcv.DBH <= maxDbh
                                       select tcv).ToList();
                  }
                  else
                  {
                     myTreeList = (from tcv in myTree
                                       where tcv.SampleGroup.PrimaryProduct == curSgStats.PrimaryProduct
                                       && tcv.Plot_CN == curPlot.Plot_CN
                                       && tcv.Species == curTdv.Species
                                       && tcv.LiveDead == curTdv.LiveDead
                                       select tcv).ToList();
                  }

                  foreach (TreeDO rTree in myTreeList)
                  {
                     fsTree = new TreeDO(fsDAL);
                     fsTree.Stratum_CN = curStrStats.Stratum_CN;
                     fsTree.TreeDefaultValue_CN = curTdv.TreeDefaultValue_CN;
                     fsTree.SampleGroup_CN = sampleGroupCN;
                     fsTree.Plot_CN = plotCN;
                     fsTree.CuttingUnit_CN = curUnit.CuttingUnit_CN;
                     fsTree.TreeNumber = rTree.TreeNumber;
                     fsTree.Species = rTree.Species;
                     fsTree.CountOrMeasure = rTree.CountOrMeasure;
                     fsTree.SeenDefectPrimary = rTree.SeenDefectPrimary;
                     fsTree.SeenDefectSecondary = rTree.SeenDefectSecondary;
                     fsTree.RecoverablePrimary = rTree.RecoverablePrimary;
                     fsTree.Initials = rTree.Initials;
                     fsTree.LiveDead = rTree.LiveDead;
                     fsTree.Grade = rTree.Grade;
                     fsTree.HeightToFirstLiveLimb = rTree.HeightToFirstLiveLimb;
                     fsTree.DBH = rTree.DBH;
                     fsTree.DRC = rTree.DRC;
                     fsTree.TotalHeight = rTree.TotalHeight;
                     fsTree.MerchHeightPrimary = rTree.MerchHeightPrimary;
                     fsTree.MerchHeightSecondary = rTree.MerchHeightSecondary;
                     fsTree.FormClass = rTree.FormClass;
                     fsTree.UpperStemHeight = rTree.UpperStemHeight;
                     fsTree.TopDIBPrimary = rTree.TopDIBPrimary;
                     fsTree.TopDIBSecondary = rTree.TopDIBSecondary;
                     fsTree.CreatedBy = rTree.CreatedBy;
                     fsTree.CreatedDate = rTree.CreatedDate;

                     fsTree.Save();
                     // save logs
                  }
               }
            }
             }
             return (0);
        }