public void SetValues(TreeFieldSetupDO obj)
		{
			if(obj == null) { return; }
			Field = obj.Field;
			FieldOrder = obj.FieldOrder;
			ColumnType = obj.ColumnType;
			Heading = obj.Heading;
			Width = obj.Width;
			Format = obj.Format;
			Behavior = obj.Behavior;
		}
        protected List<TreeFieldSetupDO> GetSelectedTreeFieldsDefault(StratumDO stratum)
        {
            //select from TreeFieldSetupDefault where method = stratum.method
            List<TreeFieldSetupDefaultDO> treeFieldDefaults = this.Database.Read<TreeFieldSetupDefaultDO>("TreeFieldSetupDefault", "WHERE Method = ? ORDER BY FieldOrder", stratum.Method);

            List<TreeFieldSetupDO> treeFields = new List<TreeFieldSetupDO>();

            foreach (TreeFieldSetupDefaultDO tfd in treeFieldDefaults)
            {
                TreeFieldSetupDO tfs = new TreeFieldSetupDO();
                tfs.Stratum_CN = stratum.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);
            }
            return treeFields;
        }
		public TreeFieldSetupDO(TreeFieldSetupDO obj) : this()
		{
		    SetValues(obj);
		}
        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 IEnumerable<TreeFieldSetupDO> ReadTreeFields()
        {
            var fields = DAL.From<TreeFieldSetupDO>()
                .Join("CuttingUnitStratum", "USING (Stratum_CN)")
                .Where("CuttingUnit_CN = ?")
                .GroupBy("Field")
                .OrderBy("FieldOrder")
                .Query(CuttingUnit_CN).ToList();

            if (fields.Count == 0)
            {
                fields.AddRange(Constants.DEFAULT_TREE_FIELDS);
            }

            //if unit has multiple tree strata
            //but stratum column is missing
            if (this.TreeStrata.Count > 1
                && fields.FindIndex(x => x.Field == "Stratum") == -1)
            {
                //find the location of the tree number field
                int indexOfTreeNum = fields.FindIndex(x => x.Field == CruiseDAL.Schema.TREE.TREENUMBER);
                //if user doesn't have a tree number field, fall back to the last field index
                if (indexOfTreeNum == -1) { indexOfTreeNum = fields.Count - 1; }//last item index
                //add the stratum field to the filed list
                TreeFieldSetupDO tfs = new TreeFieldSetupDO() { Field = "Stratum", Heading = "St", Format = "[Code]" };
                fields.Insert(indexOfTreeNum + 1, tfs);
            }

            return fields;
        }
        public IEnumerable<TreeFieldSetupDO> GetSelectedTreeFieldsDefault()
        {
            //select from TreeFieldSetupDefault where method = stratum.method
            var treeFieldDefaults = this.DAL.From<TreeFieldSetupDefaultDO>()
                .Where("Method = ?")
                .OrderBy("FieldOrder")
                .Query(Method);

            foreach (var tfd in treeFieldDefaults)
            {
                var tfs = new TreeFieldSetupDO();
                tfs.Stratum_CN = 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;

                yield return tfs;
            }
        }
        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);
        }