Exemplo n.º 1
0
        public int setupDialog()
        {
            //  first, ask the security question and only allow correct answer to proceed
            SecurityQuestion sq = new SecurityQuestion();

            sq.ShowDialog();
            if (sq.securityResponse != "OK")
            {
                Close();
                return(-1);
            }

            //  Show this message box until security question is OKd by measurement specialists.  04/2013
            //MessageBox.Show("In the future, a security question will be displayed here.", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //  if there are biomass equations, bind to grid
            //  else show message and return
            bioList = bslyr.getBiomassEquations();
            if (bioList.Count == 0)
            {
                MessageBox.Show("There are no biomass equations available for updating.\n Cannot continue.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Close();
                return(0);
            }   //  endif bioList is empty
            biomassEquationDOBindingSource.DataSource = bioList;
            biomassFactorsList.DataSource             = biomassEquationDOBindingSource;
            return(1);
        }   //  end setupDialog
Exemplo n.º 2
0
        public void setupDialog()
        {
            //  if there are biomass euqations, show in grid
            //  if not, just initialize the grid
            bslyr.fileName = fileName;
            bioList        = bslyr.getBiomassEquations();
            biomassEquationDOBindingSource.DataSource = bioList;
            biomassEquationList.DataSource            = biomassEquationDOBindingSource;

            //  cannot complete species list or equation list without the biomass library
            //  pull species/product and live/dead combinations from tree table to populate
            //  species list
            fillSpeciesList();

            //  initially equation and weight factor and insert button are disabled.
            //  if user selects an individual component then those become enabled.
            equationList.Enabled = false;
            wgt_factors.Enabled  = false;
            insertButton.Enabled = false;

            return;
        }   //  end setupDialog
        }   //  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
Exemplo n.º 4
0
        public void CreateHTMLfile()
        {
            int[] eqTables = new int[4] {
                0, 0, 0, 0
            };
            string outputFileName;
            string HTMLoutFile;

            //  need list of reports selected to build index
            List <ReportsDO> reportsSelected = bslyr.GetSelectedReports();

            //  check for equation tables with records to output
            List <VolumeEquationDO>     veList = bslyr.getVolumeEquations();
            List <ValueEquationDO>      vaList = bslyr.getValueEquations();
            List <QualityAdjEquationDO> qaList = bslyr.getQualAdjEquations();
            List <BiomassEquationDO>    bsList = bslyr.getBiomassEquations();

            if (veList.Count > 0)
            {
                eqTables[0] = 1;
            }
            if (vaList.Count > 0)
            {
                eqTables[1] = 1;
            }
            if (qaList.Count > 0)
            {
                eqTables[2] = 1;
            }
            if (bsList.Count > 0)
            {
                eqTables[3] = 1;
            }

            //  fix the output filename
            outputFileName = System.IO.Path.ChangeExtension(fileName, "out");
            //  does it exist?
            if (!File.Exists(outputFileName))
            {
                MessageBox.Show("Cannot create HTML file because the output file cannot be found.\nMake sure the output file has been created\nfor the current cruise file.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }   //  endif if does not exist

            //  create HTML filename
            HTMLoutFile = System.IO.Path.ChangeExtension(fileName, "html");

            //  need the index
            ArrayList HTMLindex = BuildTheIndex(eqTables, reportsSelected);

            //  Output records from the output file
            using (StreamWriter strWriteOut = new StreamWriter(HTMLoutFile))
            {
                //  output index first
                foreach (object obj in HTMLindex)
                {
                    strWriteOut.WriteLine(obj);
                }

                //  Read/Write records from OUT file
                string line;
                string currentRecord;
                string currentReport  = "**";
                string previousReport = "**";
                using (StreamReader strRead = new StreamReader(outputFileName))
                {
                    while ((line = strRead.ReadLine()) != null)
                    {
                        if (line == "\f")
                        {
                            //  don't put "back to index"; just a new page
                            strWriteOut.WriteLine(HTMLcommands[2]);
                        }
                        else if (line == "" || line == " ")
                        {
                            strWriteOut.WriteLine(line);
                        }
                        else if (line != "" && line != " ")
                        {
                            if (line.Contains("CRUISE REPORT HEADER"))
                            {
                                strWriteOut.WriteLine(HTMLcommands[3]);
                                strWriteOut.WriteLine(line);
                            }
                            else if (line.Contains("VOLUME EQUATION TABLE"))
                            {
                                currentReport = "VOLUME EQUATION TABLE";
                                if (previousReport != currentReport)
                                {
                                    strWriteOut.WriteLine(HTMLcommands[5]);
                                    previousReport = currentReport;
                                    strWriteOut.WriteLine(HTMLcommands[2]);
                                }
                                else
                                {
                                    strWriteOut.WriteLine(HTMLcommands[2]);
                                }
                                currentRecord = HTMLcommands[4];
                                currentRecord = currentRecord.Replace("XXXX", "VolEq");
                                currentRecord = currentRecord.Replace("XX", "Volume Equation Table");
                                strWriteOut.WriteLine(currentRecord);
                                strWriteOut.WriteLine(line);
                            }
                            else if (line.Contains("VALUE EQUATION TABLE"))
                            {
                                currentReport = "VALUE EQUATION TABLE";
                                if (previousReport != currentReport)
                                {
                                    strWriteOut.WriteLine(HTMLcommands[5]);
                                    previousReport = currentReport;
                                    strWriteOut.WriteLine(HTMLcommands[2]);
                                }
                                else
                                {
                                    strWriteOut.WriteLine(HTMLcommands[2]);
                                }
                                currentRecord = HTMLcommands[4];
                                currentRecord = currentRecord.Replace("XXXX", "ValEq");
                                currentRecord = currentRecord.Replace("XX", "Value Equation Table");
                                strWriteOut.WriteLine(currentRecord);
                                strWriteOut.WriteLine(line);
                            }
                            else if (line.Contains("QUALITY ADJUSTMENT"))
                            {
                                currentReport = "QUALITY ADJUSTMENT EQUATION TABLE";
                                if (previousReport != currentReport)
                                {
                                    strWriteOut.WriteLine(HTMLcommands[5]);
                                    previousReport = currentReport;
                                    strWriteOut.WriteLine(HTMLcommands[2]);
                                }
                                else
                                {
                                    strWriteOut.WriteLine(HTMLcommands[2]);
                                }
                                currentRecord = HTMLcommands[4];
                                currentRecord = currentRecord.Replace("XXXX", "QAEq");
                                currentRecord = currentRecord.Replace("XX", "Quality Adjustment Equation Table");
                                strWriteOut.WriteLine(currentRecord);
                                strWriteOut.WriteLine(line);
                            }
                            else if (line.Contains("BIOMASS EQUATION TABLE"))
                            {
                                currentReport = "BIOMASS EQUATION TABLE";
                                if (previousReport != currentReport)
                                {
                                    strWriteOut.WriteLine(HTMLcommands[5]);
                                    previousReport = currentReport;
                                    strWriteOut.WriteLine(HTMLcommands[2]);
                                }
                                else
                                {
                                    strWriteOut.WriteLine(HTMLcommands[2]);
                                }
                                currentRecord = HTMLcommands[4];
                                currentRecord = currentRecord.Replace("XXXX", "BiomassEq");
                                currentRecord = currentRecord.Replace("XX", "Biomass Equation Table");
                                strWriteOut.WriteLine(currentRecord);
                                strWriteOut.WriteLine(line);
                            }
                            else if (line.Contains(':'))
                            {
                                //  find out if this is a report
                                int nthRow = reportsSelected.FindIndex(
                                    delegate(ReportsDO rdo)
                                {
                                    return(rdo.ReportID == line.Substring(0, line.IndexOf(':')));
                                });
                                if (nthRow >= 0)
                                {
                                    // it's definitely a report
                                    currentReport = reportsSelected[nthRow].ReportID;
                                    if (previousReport != currentReport)
                                    {
                                        strWriteOut.WriteLine(HTMLcommands[5]);
                                        previousReport = currentReport;
                                        strWriteOut.WriteLine(HTMLcommands[2]);
                                    }
                                    else
                                    {
                                        strWriteOut.WriteLine(HTMLcommands[2]);
                                    }
                                    currentRecord = HTMLcommands[4];
                                    currentRecord = currentRecord.Replace("XXXX", currentReport);
                                    currentRecord = currentRecord.Replace("XX", currentReport);
                                    strWriteOut.WriteLine(currentRecord);
                                    strWriteOut.WriteLine(line);
                                }
                                else
                                {
                                    strWriteOut.WriteLine(line);
                                }
                            }
                            else
                            {
                                strWriteOut.WriteLine(line);
                            } //  endif line contains
                        }     //  endif
                    } //  end while read
                } //  end using read

                strWriteOut.WriteLine(HTMLcommands[5]);
                strWriteOut.WriteLine(HTMLcommands[6]);
            }   //  end using write

            //  show user where it is
            StringBuilder sb = new StringBuilder();

            sb.Append("HTML File has been created.\nIt can be found at:\n");
            sb.Append(HTMLoutFile);
            MessageBox.Show(sb.ToString(), "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information);

            return;
        }   //  end CreateHTMLfile