private void copySaleTable(DAL cDAL)
        {
            //mySale = new List<SaleDO>();
             //open sale table
             SaleDO sale = new SaleDO(cDAL.ReadSingleRow<SaleDO>("Sale", null, null));
             SaleDO fsSale = new SaleDO(fsDAL);

             fsSale.Purpose = "Timber Sale";
             fsSale.SaleNumber = sale.SaleNumber;
             fsSale.Name = sale.Name;
             fsSale.Region = sale.Region;
             fsSale.Forest = sale.Forest;
             fsSale.District = sale.District;
             fsSale.DefaultUOM = sale.DefaultUOM;
             fsSale.CalendarYear = sale.CalendarYear;
             fsSale.LogGradingEnabled = sale.LogGradingEnabled;
             fsSale.MeasurementYear = sale.MeasurementYear;
             fsSale.Remarks = sale.Remarks;

             fsSale.Save();

             logData = sale.LogGradingEnabled;

             myMeth = new List<CruiseMethodsDO>(fsDAL.Read<CruiseMethodsDO>("CruiseMethods",null,null));
             if (myMeth.Count() < 4)
             {
            myMeth.Clear();
            for (int i = 0; i < 12; i++)
            {
               CruiseMethodsDO fsMeth = new CruiseMethodsDO(fsDAL);
               addCruiseMethod(fsMeth, i);
               myMeth.Add(fsMeth);
            }
            fsDAL.Save(myMeth);
             }
        }
        private void copyCuttingUnitStrToFScruise(DAL cdDAL)
        {
            StratumDO cdStr;
             List<StratumDO> myStr = new List<StratumDO>(fsDAL.Read<StratumDO>("Stratum",null,null));
             foreach(StratumDO curStr in myStr)
             {
            cdStr = cdDAL.ReadSingleRow<StratumDO>("Stratum", "Where Code = ?", curStr.Code);
            cdStr.CuttingUnits.Populate();

            foreach (CuttingUnitDO myUnit in cdStr.CuttingUnits)
            {
               CuttingUnitStratumDO custr = new CuttingUnitStratumDO(fsDAL);
               custr.CuttingUnit_CN = myUnit.CuttingUnit_CN;
               custr.Stratum_CN = curStr.Stratum_CN;

               custr.Save();
            }
             }
        }
        private void copyPopulations(DAL cDAL, DAL rDAL, DAL fsDAL, bool reconData, string[] stRecCode)
        {
            StratumDO cdStr;
             TreeDefaultValueDO currentTDV = new TreeDefaultValueDO();
             List<StratumStatsDO> cdStratumStats = new List<StratumStatsDO>(cDAL.Read<StratumStatsDO>("StratumStats", "JOIN Stratum ON StratumStats.Stratum_CN = Stratum.Stratum_CN AND StratumStats.Method = Stratum.Method AND StratumStats.Used = 1 ORDER BY Stratum.Code", null));

             List<PlotDO> myPlots = new List<PlotDO>();
             List<TreeDO> myTree = new List<TreeDO>();
             List<LogDO> myLogs = new List<LogDO>();
             treeFields = new BindingList<TreeFieldSetupDO>();
             logFields = new BindingList<LogFieldSetupDO>();
             bool first;
             string method = "";
             Random rnd = new Random();
             int measHit;

             foreach (StratumStatsDO myStStats in cdStratumStats)
             {
            setRecData = false;
            first = true;

            // check if recon data is to be saved
            cdStr = fsDAL.ReadSingleRow<StratumDO>("Stratum", "Where Code = ?", myStStats.Code);
            string strCode = myStStats.Code;
            thisStrCN = (long)cdStr.Stratum_CN;
            if (reconData)
            {

               if (myStStats.Method == "PNT" || myStStats.Method == "PCM")
                  method = "PNT";
               else if (myStStats.Method == "FIX" || myStStats.Method == "FCM")
                  method = "FIX";

               foreach (string stRec in stRecCode)
               {
                  if (stRec == strCode)
                  {
                     setRecData = true;
                     myPlots = (rDAL.Read<PlotDO>("Plot", "JOIN Stratum ON Plot.Stratum_CN = Stratum.Stratum_CN WHERE Stratum.Method = ?", method));
                     if(myTree.Count == 0)
                     {
                        myTree = (rDAL.Read<TreeDO>("Tree", null, null));
                        myLogs = (rDAL.Read<LogDO>("Log", null, null));
                     }
                  }
               }
            }
               // get fsDAl stratum record
            List<SampleGroupStatsDO> mySgStats = new List<SampleGroupStatsDO>(cDAL.Read<SampleGroupStatsDO>("SampleGroupStats", "Where StratumStats_CN = ?", myStStats.StratumStats_CN));
               // loop through sample groups
            foreach (SampleGroupStatsDO sgStats in mySgStats)
            {
               measHit = 0;
               SampleGroupDO fsSg = new SampleGroupDO(fsDAL);
               // save sample group information
               fsSg.Stratum_CN = thisStrCN;
               fsSg.Code = sgStats.Code;
               fsSg.Description = sgStats.Description;
               fsSg.CutLeave = sgStats.CutLeave;
               fsSg.UOM = sgStats.UOM;
               fsSg.PrimaryProduct = sgStats.PrimaryProduct;
               fsSg.SecondaryProduct = sgStats.SecondaryProduct;
               fsSg.DefaultLiveDead = sgStats.DefaultLiveDead;
               fsSg.KZ = sgStats.KZ;
               fsSg.InsuranceFrequency = sgStats.InsuranceFrequency;
               if (myStStats.Method == "PCM" || myStStats.Method == "FCM")
               {
                  if (radioButton1.Checked)
                  {
                     fsSg.SamplingFrequency = sgStats.SamplingFrequency;
                     // find random start
                     int freq = (int)fsSg.SamplingFrequency;
                     measHit = rnd.Next(1, freq);
                     fsSg.BigBAF = 0;
                     fsSg.SmallFPS = 0;
                  }
                  else
                  {
                     fsSg.SamplingFrequency = 0;
                     fsSg.BigBAF = Convert.ToInt32(sgStats.BigBAF);
                     fsSg.SmallFPS = Convert.ToInt32(sgStats.BigFIX);
                  }
               }
               else
               {
                  fsSg.SamplingFrequency = sgStats.SamplingFrequency;
                  fsSg.BigBAF = 0;
                  fsSg.SmallFPS = 0;
               }
               // find treedefaultvalues
               sgStats.TreeDefaultValueStats.Populate();
               foreach (TreeDefaultValueDO tdv in sgStats.TreeDefaultValueStats)
               {
                  fsSg.TreeDefaultValues.Add(tdv);
               }
               fsSg.Save();
               fsSg.TreeDefaultValues.Save();
               // if recon can be saved
               if (setRecData)
               {
                  getReconData(myStStats, sgStats, rDAL, fsDAL, myPlots, myTree, myLogs, fsSg.SampleGroup_CN, first, measHit);
                 first = false;
               }
            }

            getTreeFieldSetup(cDAL,fsDAL,myStStats);
            if(logData)
               getLogFieldSetup(cDAL,fsDAL,myStStats);
             }
        }
        //private static void ClearFieldData(DAL database)
        //{
        //    database.Execute(CSM.Utility.SQL.CLEAR_FIELD_DATA);
        //}
        //inserts Component Records into master
        private static List<ComponentDO> BuildMasterComponentTable(DAL masterDAL, int numComp)
        {
            string masterFileName = System.IO.Path.GetFileName(masterDAL.Path);
            List<ComponentDO> compList = new List<ComponentDO>();
            for (int i = 1; i <= numComp; i++)
            {
                String compFileName = GetCompFileName(masterFileName, i);
                ComponentDO compInfo = masterDAL.ReadSingleRow<ComponentDO>("Component", "WHERE FileName = ?", compFileName);
                if (compInfo == null)
                {
                    compInfo = new ComponentDO(masterDAL);
                    compInfo.GUID = Guid.NewGuid().ToString();
                    compInfo.FileName = compFileName;
                    compInfo.Save();
                }

                compList.Add(compInfo);
            }
            return compList;
        }