Esempio 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
        public int setupDialog()
        {
            VolumeEqMethods Veq = new VolumeEqMethods();
            //  fill species list from tree table
            //  show message box if this is BLM
            string currRegion = bslyr.getRegion();

            if (currRegion == "7" || currRegion == "07")
            {
                MessageBox.Show("BLM Volume Equations cannot be entered here.", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Close();
                return(-1);
            }   //  endif BLM

            //  if there are volume equations, show in grid
            //  if not, the grid is just initialized
            equationList = bslyr.getVolumeEquations();

            //  Check for missing common name and model name
            Veq.updateVolumeList(equationList, fileName, currRegion);

            string[,] speciesProduct;
            speciesProduct = bslyr.GetUniqueSpeciesProduct();
            //  pull species not used in the cruise from the equations list
            equationList = updateEquationList(speciesProduct);

            //  If there are no species/products in tree default values, it's wrong
            //  tell user to check the file design in CSM --  June 2013
            if (speciesProduct.Length == 0)
            {
                MessageBox.Show("No species/product combinations found in Tree records.\nPlease enter tree records before continuing.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
                return(-1);
            }   //  endif

            //  if equation list is empty, just fill in unique species and primary product
            if (equationList.Count == 0)
            {
                for (int k = 0; k < speciesProduct.GetLength(0); k++)
                {
                    if (speciesProduct[k, 0] != "" && speciesProduct[k, 0] != null)
                    {
                        VolumeEquationDO ved = new VolumeEquationDO();
                        ved.Species        = speciesProduct[k, 0];
                        ved.PrimaryProduct = speciesProduct[k, 1];
                        equationList.Add(ved);
                    } //  endif end of list
                }     //  end for k loop
            }
            else
            {
                //  situation exists were a template file was made from an existing cruise and
                //  additional species/product combinations were placed in tree default value
                //  need to add those to the equationList so user can enter equation information
                //  June 2013
                for (int k = 0; k < speciesProduct.GetLength(0); k++)
                {
                    if (speciesProduct[k, 0] != "" && speciesProduct[k, 0] != null)
                    {
                        //  see if this combination is in the equationList
                        int nthRow = equationList.FindIndex(
                            delegate(VolumeEquationDO ved)
                        {
                            return(ved.Species == speciesProduct[k, 0] && ved.PrimaryProduct == speciesProduct[k, 1]);
                        });
                        if (nthRow == -1)
                        {
                            //  add the equation to the list so the user can enter equation information
                            VolumeEquationDO v = new VolumeEquationDO();
                            v.Species        = speciesProduct[k, 0];
                            v.PrimaryProduct = speciesProduct[k, 1];
                            equationList.Add(v);
                        } //  endif
                    }     //  endif
                }         //  end for k loop
            }             //  endif list is empty

            volumeEquationDOBindingSource.DataSource = equationList;
            volumeEquationList.DataSource            = volumeEquationDOBindingSource;

            //  also add species and product to combo boxes at bottom
            ArrayList justSpecies = bslyr.GetJustSpecies("TreeDefaultValue");

            for (int n = 0; n < justSpecies.Count; n++)
            {
                speciesList.Items.Add(justSpecies[n].ToString());
            }

            ArrayList justProduct = bslyr.GetJustPrimaryProduct();

            for (int n = 0; n < justProduct.Count; n++)
            {
                productList.Items.Add(justProduct[n].ToString());
            }

            volRegion.Enabled   = false;
            volForest.Enabled   = false;
            volEquation.Enabled = false;
            speciesList.Enabled = false;
            productList.Enabled = false;
            return(1);
        }   //  end setupDialog
Esempio n. 3
0
        }   //  end onTopwoodClick

        private void onOK(object sender, EventArgs e)
        {
            //  open volume equation table and remove all before building and saving equations
            bslyr.deleteVolumeEquations();
            volList.Clear();

            //  Need to build volume equation and store in table, so goes into VolumeEqList
            string        currentForest   = "";
            string        currentDistrict = "";
            string        currGeoCode     = "";
            string        currGrpCode     = "";
            List <SaleDO> saleList        = bslyr.getSale();

            foreach (SaleDO sd in saleList)
            {
                currentForest = sd.Forest;
                if (sd.District == null)
                {
                    currentDistrict = "";
                }
                else
                {
                    currentDistrict = sd.District;
                }
            }   //  end foreach

            //  Look up geo code and group code for this forest and district (if any)
            //  First look in defaults
            for (int k = 0; k < 12; k++)
            {
                if (currentForest == forestDefaultList[k, 0])
                {
                    currGeoCode = forestDefaultList[k, 1];
                    currGrpCode = forestDefaultList[k, 2];
                } //  endif
            }     //  end for k loop

            //  Check for an override on district
            for (int k = 0; k < 33; k++)
            {
                if (currentForest == forestDistrictList[k, 0] && currentDistrict == forestDistrictList[k, 1])
                {
                    currGeoCode = forestDistrictList[k, 2];
                    currGrpCode = forestDistrictList[k, 3];
                } //  endif
            }     //  end for k loop

            //  if geocode and group code are still blank, means forest or district are incorrect
            if (currGeoCode == "" || currGrpCode == "")
            {
                MessageBox.Show("Could not find Forest and/or District number.\nCannot complete equations.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
                return;
            }   //  endif

            //  get unique species/product combinations
            string[,] speciesProduct = bslyr.GetUniqueSpeciesProduct();
            for (int k = 0; k < speciesProduct.GetLength(0); k++)
            {
                //  need species and product
                string currentSpecies = speciesProduct[k, 0];
                string currentProduct = speciesProduct[k, 1];

                //  call build equation for this combination
                if (currentSpecies != null && currentProduct != null)
                {
                    //  change in volume library no longer has DVEE equations used for board for board foot volume
                    //  so commented out the call to build those equations
                    //  October 2015
                    //if (currentProduct == "01")
                    //  buildVolumeEquation(currGrpCode, currentSpecies, currentProduct);
                    //  Build Clark equations -- old or new -- July 2017
                    if (newClarkCheckBox.Checked == true)
                    {
                        buildNewClarkEquations(currGeoCode, currentSpecies, currentProduct);
                    }
                    else if (oldClarkCheckBox.Checked == true)
                    {
                        if (pulpwoodHeight >= 0)
                        {
                            buildClarkEquation(currGeoCode, currentSpecies, currentProduct, pulpwoodHeight);
                        }
                        else if (pulpwoodHeight < 0)
                        {
                            Close();
                            return;
                        } //  endif
                    }     //  endif
                }         //  endif no null
            }             //  end foreach

            //  Save equations in database
            bslyr.SaveVolumeEquations(volList);

            if (calcBiomass.Checked == true)
            {
                VolumeEquations ve = new VolumeEquations();
                ve.bslyr.fileName = fileName;
                ve.fileName       = fileName;
                ve.bslyr.DAL      = bslyr.DAL;
                ve.updateBiomass(volList);
            }   //  endif calculate biomass
            Close();
            return;
        }   //  end onOK