Exemplo n.º 1
0
        private bool checkProcessedFile(DAL pDAL)
        {
            // get LCD file
             List<LCDDO> selectedLCD = pDAL.Read<LCDDO>("LCD", null, null);

             // if NULL, return false
             if (selectedLCD.Count == 0)
            return (false);

             // else, return true
             return (true);
        }
        private void copyStratumToFScruise(DAL cdDAL)
        {
            //loop through design stratum table
             List<StratumDO> myStr = new List<StratumDO>(cdDAL.Read<StratumDO>("Stratum",null,null));
             foreach(StratumDO curStr in myStr)
             {
             // create new stratumDO
            StratumDO fsStr = new StratumDO(fsDAL);
             // copy stratum information
            fsStr.Code = curStr.Code;
            fsStr.Description = curStr.Description;
            fsStr.Method = curStr.Method;
            fsStr.BasalAreaFactor = curStr.BasalAreaFactor;
            fsStr.FixedPlotSize = curStr.FixedPlotSize;
            fsStr.KZ3PPNT = curStr.KZ3PPNT;
            fsStr.YieldComponent = curStr.YieldComponent;
            fsStr.Year = curStr.Year;
            fsStr.Month = curStr.Month;

            fsStr.Save();

             }
        }
        public void getProductionStats(DAL cDAL, int err)
        {
            cdDAL = cDAL;

             // set up StratumStats, SampleGroupStats

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

             // loop through stratum
             foreach (StratumDO curStr in stratum)
             {

            getPopulations(curStr);

             }
        }
 private void checkContrSpecies(DAL fsDAL)
 {
     List<TreeDefaultValueDO> treeDV = new List<TreeDefaultValueDO>(fsDAL.Read<TreeDefaultValueDO>("TreeDefaultValue", null, null));
      foreach (TreeDefaultValueDO tdv in treeDV)
      {
     if (tdv.ContractSpecies == null || tdv.ContractSpecies == "")
     {
        tdv.ContractSpecies = tdv.Species;
        tdv.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);
             }
        }
        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 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);
        }
        private void copyPopulations(DAL cDAL, DAL rDAL, DAL fsDAL, bool reconData, string[] stRecCode)
        {
            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>();
             BindingList<TreeFieldSetupDO> treeFields = new BindingList<TreeFieldSetupDO>();
             bool first;
             string method = "";

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

            // check if recon data is to be saved
            if (reconData)
            {
               string strCode = myStStats.Code;

               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));
                  }
               }
            }
               // 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)
            {
               SampleGroupDO fsSg = new SampleGroupDO(fsDAL);
               // save sample group information
               fsSg.Stratum_CN = sgStats.StratumStats.Stratum_CN;
               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 (checkBoxFreq.Checked)
                  {
                     fsSg.SamplingFrequency = sgStats.SamplingFrequency;
                     fsSg.BigBAF = 0;
                  }
                  else
                  {
                     fsSg.SamplingFrequency = 0;
                     fsSg.BigBAF = Convert.ToInt32(sgStats.BigBAF);
                  }

               }
               else
               {
                  fsSg.SamplingFrequency = sgStats.SamplingFrequency;
                  fsSg.BigBAF = Convert.ToInt32(sgStats.BigBAF);
               }
               // 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, fsSg.SampleGroup_CN, first);
                  // get plot data
                  first = false;
                  // get tree data
                  // get log data
               }
            }
            //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 = myStStats.Stratum_CN;
               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 void StrataTest2()
        {
            //here we are going to copy all the cutting units
            //and all the strata belonging to them from one database
            //to another, along with the many-to-many relationships between them.

            //To do this we need to remember that the CuttingUnitStratum table
            //needs to know the CN values of both the cutting unit and the stratum
            //before a mapping can be made. To do that we need to save the strata and
            //cutting units before we save the mappings.

            DAL originDAL = new DAL(TEST_FILE_PATH);
            DAL destDAL = new DAL("StrataTest2.cruise", true);

            var cuttingUnits = originDAL.Read<CuttingUnitDO>("CuttingUnit", null, null);

            //here we want to make sure all the strata
            //we will be coping are loaded into memory
            //because once we start coping we don't want
            //to reread any strata untill we are done
            foreach (CuttingUnitDO cu in cuttingUnits)
            {
                cu.Strata.Populate();
            }

            //next we want to save all the strata into
            //our destination database so we know
            //their CN values for the next step

            foreach (CuttingUnitDO cu in cuttingUnits)
            {
                foreach (StratumDO st in cu.Strata)
                {
                    if (st.DAL != destDAL)
                    {
                        st.DAL = destDAL;
                        st.Save();
                    }
                }
            }

            //now that we know that all the strata have
            //their new CNs, we need to save the cuttingUnits
            //and get their new CNs too.
            //We can also save the mapping collection during
            //this step, because the CN value on the CuttingUnit
            //is the last thing we need to create all the mappings
            //for a given cutting unit
            foreach (CuttingUnitDO cu in cuttingUnits)
            {
                cu.DAL = destDAL;
                cu.Save();
                cu.Strata.Save();
            }
        }
Exemplo n.º 10
0
        public void ReadOneAllTablesCore(DAL db)
        {
            ArrayList results = new ArrayList();

            results.Add(db.Read<CruiseDAL.DataObjects.BiomassEquationDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.ComponentDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.CountTreeDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.CruiseMethodsDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.CuttingUnitDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.CuttingUnitStratumDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.ErrorLogDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.ForestsDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.GlobalsDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.LCDDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.LogDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.LogFieldSetupDefaultDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.LogFieldSetupDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.LoggingMethodsDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.LogMatrixDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.LogStockDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.MessageLogDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.PlotDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.POPDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.PRODO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.ProductCodesDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.QualityAdjEquationDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.RegionsDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.RegressionDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.ReportsDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.SaleDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.SampleGroupDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.SampleGroupStatsDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.SampleGroupStatsTreeDefaultValueDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.SampleGroupTreeDefaultValueDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.StemDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.StratumDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.StratumStatsDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.TallyDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.TreeAuditValueDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.TreeCalculatedValuesDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.TreeDefaultValueDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.TreeDefaultValueTreeAuditValueDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.TreeDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.TreeEstimateDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.TreeFieldSetupDefaultDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.TreeFieldSetupDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.UOMCodesDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.ValueEquationDO>(null, null));
            results.Add(db.Read<CruiseDAL.DataObjects.VolumeEquationDO>(null, null));
            //results.Add(db.Read<CruiseDAL.DataObjects.StratumAcres_ViewDO>(null, null));

            //List<CruiseDAL.DataObjects.CountTree_ViewDO> ctv = db.Read<CruiseDAL.DataObjects.CountTree_ViewDO>(null, null);
            //foreach (CruiseDAL.DataObjects.CountTree_ViewDO ct in ctv)
            //{
            //    TestContext.WriteLine(ct.ToString());
            //}
            //results.Add(ctv);

            foreach (object obj in results)
            {
                IList inst = obj as IList;

                Assert.IsTrue(obj != null);
                Assert.IsTrue(inst != null);
                Assert.IsTrue(inst.Count > 0, "Expected " + inst.ToString() + " to contain items");
            }
        }