Exemplo n.º 1
0
        }   //  end onFinished

        private void CreateEquations(string eqnPrefix)
        {
            string currentProduct;
            string currentSpecies;

            //  Need to capture DIBs before creating equations
            List <JustDIBs> oldDIBs = bslyr.GetJustDIBs();

            //  Grab tree data grouped by unique species and products
            string[,] speciesProduct;
            speciesProduct = bslyr.GetUniqueSpeciesProduct();

            StringBuilder sb = new StringBuilder();
            double        updatedPrimaryDIB   = 0.0;
            double        updatedSecondaryDIB = 0.0;

            for (int k = 0; k < speciesProduct.GetLength(0); k++)
            {
                if (speciesProduct[k, 0] != null)
                {
                    VolumeEquationDO vel = new VolumeEquationDO();
                    //  Per Mike VanDyck --  cords flag is on for everything including sawtimber
                    vel.CalcCord = 1;

                    //  Set constant values
                    vel.CalcTotal           = 0;
                    vel.StumpHeight         = 0;
                    vel.TopDIBPrimary       = 0;
                    vel.TopDIBSecondary     = 0;
                    vel.Trim                = 0;
                    vel.SegmentationLogic   = 0;
                    vel.MaxLogLengthPrimary = 0;
                    vel.MinLogLengthPrimary = 0;
                    vel.MinMerchLength      = 0;

                    currentProduct = speciesProduct[k, 1];
                    currentSpecies = speciesProduct[k, 0];

                    //  build equation
                    sb.Clear();
                    sb.Append(eqnPrefix);
                    //  Fix species code as needed
                    if (currentSpecies.Length == 2)
                    {
                        sb.Append("0");
                    }
                    else if (currentSpecies.Length == 1)
                    {
                        sb.Append("00");
                    }
                    sb.Append(currentSpecies);
                    vel.VolumeEquationNumber = sb.ToString();

                    //  Set calculation flags as needed
                    vel.CalcCubic   = 1;
                    vel.CalcTopwood = 0;
                    if (currentProduct == "01")
                    {
                        vel.CalcBoard = 1;
                        //  Is topwood status changed for this species
                        if (topwoodSpecies.IndexOf(currentSpecies) >= 0)
                        {
                            vel.CalcTopwood = Convert.ToInt32(topwoodFlags[topwoodSpecies.IndexOf(currentSpecies)]);
                        }
                    }
                    else
                    {
                        vel.CalcBoard = 0;
                    }

                    if (eqnPrefix == "900DVEE")
                    {
                        //  Need to update DIB values here
                        UpdateDIBs(oldDIBs, currentSpecies, currentProduct, updatedPrimaryDIB, updatedSecondaryDIB);
                        vel.TopDIBPrimary   = Convert.ToSingle(updatedPrimaryDIB);
                        vel.TopDIBSecondary = Convert.ToSingle(updatedSecondaryDIB);
                    }
                    else if (eqnPrefix == "900CLKE")
                    {
                        //  See if DIB exists in the old DIB list for this species
                        int nthRow = oldDIBs.FindIndex(
                            delegate(JustDIBs jds)
                        {
                            return(jds.speciesDIB == currentSpecies);
                        });
                        if (nthRow >= 0)
                        {
                            vel.TopDIBPrimary   = Convert.ToSingle(oldDIBs[nthRow].primaryDIB);
                            vel.TopDIBSecondary = Convert.ToSingle(oldDIBs[nthRow].secondaryDIB);
                        }
                        else if (nthRow < 0)
                        {
                            //  Was it updated by the user?
                            int mthRow = jstDIBs.FindIndex(
                                delegate(JustDIBs jds)
                            {
                                //  based on conversation with M.VanDyck, Sept 2014, any DIB change applies to
                                // any primary product value, sawtimber or non-sawtimber.  Removed check for product.
                                return(jds.speciesDIB == currentSpecies);
                            });
                            if (mthRow >= 0)
                            {
                                //  Sawtimber
                                if (jstDIBs[mthRow].primaryDIB == 0.0)
                                {
                                    //  set to default
                                    if (Convert.ToInt32(currentSpecies) < 300)
                                    {
                                        vel.TopDIBPrimary = Convert.ToSingle(defaultConiferTop);
                                    }
                                    else
                                    {
                                        vel.TopDIBPrimary = Convert.ToSingle(defaultHardwoodTop);
                                    }
                                }
                                else
                                {
                                    vel.TopDIBPrimary = Convert.ToSingle(jstDIBs[mthRow].primaryDIB);
                                }

                                //  Non-saw
                                if (jstDIBs[mthRow].secondaryDIB == 0.0)
                                {
                                    vel.TopDIBSecondary = Convert.ToSingle(defaultNonSaw);
                                }
                                else
                                {
                                    vel.TopDIBSecondary = Convert.ToSingle(jstDIBs[mthRow].secondaryDIB);
                                }
                            }
                            else if (mthRow < 0)
                            {
                                //  set to defaults
                                if (Convert.ToInt32(currentSpecies) < 300)
                                {
                                    vel.TopDIBPrimary = Convert.ToSingle(defaultConiferTop);
                                }
                                else
                                {
                                    vel.TopDIBPrimary = Convert.ToSingle(defaultHardwoodTop);
                                }

                                vel.TopDIBSecondary = Convert.ToSingle(defaultNonSaw);
                            } //  endif mthRow
                        }     //  endif nthRow
                    }         //  endif eqnPrefix
                    vel.Species        = currentSpecies;
                    vel.PrimaryProduct = currentProduct;
                    if (calcBiomass.Checked == true)
                    {
                        vel.CalcBiomass = 1;
                    }
                    else
                    {
                        vel.CalcBiomass = 0;
                    }
                    volList.Add(vel);
                } //  endif not blank or null
            }     //  end for k loop

            return;
        }   //  end CreateEquations