}   //  end onDelete

        public void updateBiomass(List <VolumeEquationDO> equationList, string currRegion, string currForest)
        {
            //  function only updates biomass equations in a template file
            List <TreeDefaultValueDO> treeDef = bslyr.getTreeDefaults();
            List <BiomassEquationDO>  bioList = bslyr.getBiomassEquations();

            if (bioList.Count > 0)
            {
                bslyr.ClearBiomassEquations();
            }

            //  capture percent removed
            List <PercentRemoved> prList = new List <PercentRemoved>();

            foreach (VolumeEquationDO vdo in equationList)
            {
                PercentRemoved pr = new PercentRemoved();
                if (vdo.CalcBiomass == 1)
                {
                    pr.bioSpecies = vdo.Species;
                    pr.bioProduct = vdo.PrimaryProduct;
                    prList.Add(pr);
                } //  endif biomass flag checked
            }     //  end foreach
            if (prList.Count > 0)
            {
                CapturePercentRemoved cpr = new CapturePercentRemoved();
                cpr.prList = prList;
                cpr.setupDialog();
                cpr.ShowDialog();
                prList = cpr.prList;
            }   //  endif nthRow

            //  new variables for biomass call
            int REGN, SPCD;

            float[]       WF     = new float[3];
            StringBuilder AGTEQ  = new StringBuilder(256);
            StringBuilder LBREQ  = new StringBuilder(256);
            StringBuilder DBREQ  = new StringBuilder(256);
            StringBuilder FOLEQ  = new StringBuilder(256);
            StringBuilder TIPEQ  = new StringBuilder(256);
            StringBuilder WF1REF = new StringBuilder(256);
            StringBuilder WF2REF = new StringBuilder(256);
            StringBuilder MCREF  = new StringBuilder(256);
            StringBuilder AGTREF = new StringBuilder(256);
            StringBuilder LBRREF = new StringBuilder(256);
            StringBuilder DBRREF = new StringBuilder(256);
            StringBuilder FOLREF = new StringBuilder(256);
            StringBuilder TIPREF = new StringBuilder(256);
            const int     strlen = 256;

            //  need an array of component titles
            string[] componentArray = new string[7] {
                "TotalTreeAboveGround", "LiveBranches", "DeadBranches", "Foliage", "PrimaryProd", "SecondaryProd", "StemTip"
            };
            //  convert region to integer and forest to StringBuilder
            REGN = Convert.ToInt16(currRegion);
            StringBuilder FORST = new StringBuilder(256);

            FORST.Append(currForest);

            foreach (VolumeEquationDO el in equationList)
            {
                if (el.CalcBiomass == 1)
                {
                    // find species/product in tree default values for FIA code
                    int nthRow = treeDef.FindIndex(
                        delegate(TreeDefaultValueDO td)
                    {
                        return(td.Species == el.Species && td.PrimaryProduct == el.PrimaryProduct);
                    });
                    if (nthRow >= 0)
                    {
                        WF[0] = 0;
                        WF[1] = 0;
                        WF[2] = 0;
                        SPCD  = Convert.ToInt16(treeDef[nthRow].FIAcode);
                        CRZSPDFTCS(ref REGN, FORST, ref SPCD, WF, AGTEQ, LBREQ, DBREQ, FOLEQ, TIPEQ,
                                   WF1REF, WF2REF, MCREF, AGTREF, LBRREF, DBRREF, FOLREF, TIPREF,
                                   strlen, strlen, strlen, strlen, strlen, strlen, strlen, strlen,
                                   strlen, strlen, strlen, strlen, strlen, strlen);

                        //  get percent removed from list
                        float currPC = new float();
                        int   ithRow = prList.FindIndex(
                            delegate(PercentRemoved pr)
                        {
                            return(pr.bioSpecies == el.Species && pr.bioProduct == el.PrimaryProduct);
                        });

                        for (int k = 0; k < 7; k++)
                        {
                            BiomassEquationDO bedo = new BiomassEquationDO();
                            bedo.FIAcode         = treeDef[nthRow].FIAcode;
                            bedo.LiveDead        = treeDef[nthRow].LiveDead;
                            bedo.Product         = el.PrimaryProduct;
                            bedo.Species         = el.Species;
                            bedo.PercentMoisture = WF[2];
                            bedo.PercentRemoved  = currPC;

                            //  switch through component array
                            switch (k)
                            {
                            case 0:         //  Total tree above ground
                                bedo.Component = componentArray[k];
                                bedo.Equation  = AGTEQ.ToString();
                                bedo.MetaData  = AGTREF.ToString();
                                break;

                            case 1:         //  Live branches
                                bedo.Component = componentArray[k];
                                bedo.Equation  = LBREQ.ToString();
                                bedo.MetaData  = LBRREF.ToString();
                                break;

                            case 2:         //  Dead branches
                                bedo.Component = componentArray[k];
                                bedo.Equation  = DBREQ.ToString();
                                bedo.MetaData  = DBRREF.ToString();
                                break;

                            case 3:         //  Foliage
                                bedo.Component = componentArray[k];
                                bedo.Equation  = FOLEQ.ToString();
                                bedo.MetaData  = FOLREF.ToString();
                                break;

                            case 4:         //  Primary product
                                bedo.Component = componentArray[k];
                                bedo.Equation  = "";
                                if (currRegion == "05" || currRegion == "5")
                                {
                                    //  setip array for FFIA codes for applicable species
                                    long[] FIAcodes = new long[8] {
                                        122, 116, 117, 015, 020, 202, 081, 108
                                    };
                                    if (el.PrimaryProduct == "20")
                                    {
                                        for (int j = 0; j < 8; j++)
                                        {
                                            if (treeDef[nthRow].FIAcode == FIAcodes[j])
                                            {
                                                bedo.WeightFactorPrimary = WF[1];
                                            }
                                        }
                                    }
                                    else
                                    {
                                        bedo.WeightFactorPrimary = WF[0];
                                    }
                                }
                                else
                                {
                                    bedo.WeightFactorPrimary = WF[0];
                                }
                                bedo.MetaData = WF1REF.ToString();
                                break;

                            case 5:         //  Secondary product
                                bedo.Component             = componentArray[k];
                                bedo.Equation              = "";
                                bedo.WeightFactorSecondary = WF[1];
                                bedo.MetaData              = WF2REF.ToString();
                                break;

                            case 6:         //  Stem tip
                                bedo.Component = componentArray[k];
                                bedo.Equation  = TIPEQ.ToString();
                                bedo.MetaData  = TIPREF.ToString();
                                break;
                            }   //  end switch

                            bioList.Add(bedo);
                        } //  end for k loop
                    }     //  endif nthRow
                }         //  endif
            }             //  end foreach loop

            //  save list
            bslyr.SaveBiomassEquations(bioList);
            return;
        }
        }   //  end onCancel

        public void updateBiomass(List <VolumeEquationDO> equationList)
        {
            List <TreeDO> treeList = bslyr.getTrees();
            //  Are there records in the BiomassEquation table?  Remove all
            List <BiomassEquationDO> bioList = bslyr.getBiomassEquations();

            if (bioList.Count > 0)
            {
                bslyr.ClearBiomassEquations();
            }
            //  need to reset filename
            bslyr.fileName = fileName;
            string currRegion = bslyr.getRegion();
            string currForest = bslyr.getForest();
            //  district is not used in the new biomass library call
            //string currDist = bslyr.getDistrict();

            //  if just one volume equation has biomass flag checked, need to capture percent removed for any or all
            List <PercentRemoved> prList = new List <PercentRemoved>();

            foreach (VolumeEquationDO vdo in equationList)
            {
                PercentRemoved pr = new PercentRemoved();
                if (vdo.CalcBiomass == 1)
                {
                    pr.bioSpecies = vdo.Species;
                    pr.bioProduct = vdo.PrimaryProduct;
                    prList.Add(pr);
                } //  endif biomass flag checked
            }     //  end foreach
            if (prList.Count > 0)
            {
                CapturePercentRemoved cpr = new CapturePercentRemoved();
                cpr.prList = prList;
                cpr.setupDialog();
                cpr.ShowDialog();
                prList = cpr.prList;
            }   //  endif nthRow

            //  new variables for biomass call
            int REGN, SPCD;

            float[]       WF     = new float[3];
            StringBuilder AGTEQ  = new StringBuilder(256);
            StringBuilder LBREQ  = new StringBuilder(256);
            StringBuilder DBREQ  = new StringBuilder(256);
            StringBuilder FOLEQ  = new StringBuilder(256);
            StringBuilder TIPEQ  = new StringBuilder(256);
            StringBuilder WF1REF = new StringBuilder(256);
            StringBuilder WF2REF = new StringBuilder(256);
            StringBuilder MCREF  = new StringBuilder(256);
            StringBuilder AGTREF = new StringBuilder(256);
            StringBuilder LBRREF = new StringBuilder(256);
            StringBuilder DBRREF = new StringBuilder(256);
            StringBuilder FOLREF = new StringBuilder(256);
            StringBuilder TIPREF = new StringBuilder(256);
            const int     strlen = 256;

            //  need an array of component titles
            string[] componentArray = new string[7] {
                "TotalTreeAboveGround", "LiveBranches", "DeadBranches", "Foliage", "PrimaryProd", "SecondaryProd", "StemTip"
            };
            //  convert region to integer and forest to StringBuilder
            REGN = Convert.ToInt16(currRegion);
            StringBuilder FORST = new StringBuilder(256);

            FORST.Append(currForest);

            //  Region 8 does things so differently -- multiple species could be
            //  in the equation list so need to check for duplicates.  Otherwise, the biomass equations
            //  won't save.  February 2014
            string prevSP = "**";
            string prevPP = "**";

            //  update biomass equations
            foreach (VolumeEquationDO vedo in equationList)
            {
                if (vedo.CalcBiomass == 1)
                {
                    if (prevSP != vedo.Species || (prevSP == vedo.Species && prevPP != vedo.PrimaryProduct))
                    {
                        prevSP = vedo.Species;
                        prevPP = vedo.PrimaryProduct;
                        //  find species/product in Tree list
                        int nthRow = treeList.FindIndex(
                            delegate(TreeDO t)
                        {
                            return(t.Species == vedo.Species && t.SampleGroup.PrimaryProduct == vedo.PrimaryProduct);
                        });

                        if (nthRow >= 0)
                        {
                            WF[0] = 0;
                            WF[1] = 0;
                            WF[2] = 0;
                            SPCD  = Convert.ToInt16(treeList[nthRow].TreeDefaultValue.FIAcode);
                            CRZSPDFTCS(ref REGN, FORST, ref SPCD, WF, AGTEQ, LBREQ, DBREQ, FOLEQ, TIPEQ,
                                       WF1REF, WF2REF, MCREF, AGTREF, LBRREF, DBRREF, FOLREF, TIPREF,
                                       strlen, strlen, strlen, strlen, strlen, strlen, strlen, strlen,
                                       strlen, strlen, strlen, strlen, strlen, strlen);

                            //  get percent removed from list
                            float currPC = new float();
                            int   ithRow = prList.FindIndex(
                                delegate(PercentRemoved pr)
                            {
                                return(pr.bioSpecies == vedo.Species && pr.bioProduct == vedo.PrimaryProduct);
                            });
                            if (ithRow >= 0)
                            {
                                currPC = Convert.ToSingle(prList[ithRow].bioPCremoved);
                            }
                            else
                            {
                                currPC = 0;
                            }

                            for (int k = 0; k < 7; k++)
                            {
                                BiomassEquationDO bedo = new BiomassEquationDO();
                                bedo.FIAcode         = treeList[nthRow].TreeDefaultValue.FIAcode;
                                bedo.LiveDead        = treeList[nthRow].LiveDead;
                                bedo.Product         = vedo.PrimaryProduct;
                                bedo.Species         = vedo.Species;
                                bedo.PercentMoisture = WF[2];
                                bedo.PercentRemoved  = currPC;

                                //  switch through component array
                                switch (k)
                                {
                                case 0:         //  Total tree above ground
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = AGTEQ.ToString();
                                    bedo.MetaData  = AGTREF.ToString();
                                    break;

                                case 1:         //  Live branches
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = LBREQ.ToString();
                                    bedo.MetaData  = LBRREF.ToString();
                                    break;

                                case 2:         //  Dead branches
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = DBREQ.ToString();
                                    bedo.MetaData  = DBRREF.ToString();
                                    break;

                                case 3:         //  Foliage
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = FOLEQ.ToString();
                                    bedo.MetaData  = FOLREF.ToString();
                                    break;

                                case 4:         //  Primary product
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = "";
                                    if (currRegion == "05" || currRegion == "5")
                                    {
                                        //  setip array for FIA codes for applicable species
                                        long[] FIAcodes = new long[8] {
                                            122, 116, 117, 015, 020, 202, 081, 108
                                        };
                                        int foundIt = 0;
                                        if (vedo.PrimaryProduct == "20")
                                        {
                                            for (int j = 0; j < 8; j++)
                                            {
                                                if (treeList[nthRow].TreeDefaultValue.FIAcode == FIAcodes[j])
                                                {
                                                    bedo.WeightFactorPrimary = WF[1];
                                                    foundIt = 1;
                                                }
                                            }       //  end for j loop
                                            if (foundIt == 0)
                                            {
                                                bedo.WeightFactorPrimary = WF[0];
                                            }
                                        }
                                        else
                                        {
                                            bedo.WeightFactorPrimary = WF[0];
                                        }
                                    }
                                    else
                                    {
                                        bedo.WeightFactorPrimary = WF[0];
                                    }
                                    bedo.MetaData = WF1REF.ToString();
                                    break;

                                case 5:         //  Secondary product
                                    bedo.Component             = componentArray[k];
                                    bedo.Equation              = "";
                                    bedo.WeightFactorSecondary = WF[1];
                                    bedo.MetaData              = WF2REF.ToString();
                                    break;

                                case 6:         //  Stem tip
                                    bedo.Component = componentArray[k];
                                    bedo.Equation  = TIPEQ.ToString();
                                    bedo.MetaData  = TIPREF.ToString();
                                    break;
                                }   //  end switch

                                bioList.Add(bedo);
                            } //  end for k loop
                        }     //  endif nthRow
                    }         //  endif species and product are not equal
                }             //  endif biomass checked
            }                 //  end foreach loop
            //  save list
            bslyr.SaveBiomassEquations(bioList);
            bslyr.fileName = fileName;
        }   //  end updateBiomass