Esempio n. 1
0
        private void on_GO(object sender, EventArgs e)
        {
            processingStatus.Text = "READY TO BEGIN?  Click GO.";
            Cursor.Current        = Cursors.WaitCursor;
            //  perform edit checks --
            processingStatus.Text = "Edit checking the data.  Please wait.";
            processingStatus.Refresh();
            //  calls edit check routines
            string outputFileName;
            //  check for errors from FScruiser before running edit checks
            //  generate an error report
            //  June 2013
            List <ErrorLogDO> fscList = Global.BL.getErrorMessages("E", "FScruiser").ToList();

            if (fscList.Count > 0)
            {
                ErrorReport eRpt = new ErrorReport();
                eRpt.fileName  = fileName;
                outputFileName = eRpt.PrintFScruiserErrors(fscList);
                string outputMessage = "ERRORS FROM FSCRUISER FOUND!\nCorrect data and rerun\nOutput file is:" + outputFileName;
                MessageBox.Show(outputMessage, "ERRORS", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //  request made to open error report in preview -- May 2015
                PrintPreview pp = new PrintPreview();
                pp.fileName = outputFileName;
                pp.setupDialog();
                pp.ShowDialog();
                Environment.Exit(0);
            }   //  endif report needed

            //  clear out error log table for just CruiseProcessing before performing checks
            Global.BL.DeleteErrorMessages();

            EditChecks eChecks = new EditChecks();

            eChecks.fileName = fileName;

            List <SaleDO>        saleList = Global.BL.getSale().ToList();
            List <SampleGroupDO> sgList   = Global.BL.getSampleGroups().ToList();
            List <StratumDO>     sList    = Global.BL.getStratum().ToList();
            List <CountTreeDO>   ctList   = Global.BL.getCountTrees().ToList();
            List <TreeDO>        tList    = Global.BL.getTrees().ToList();

            int errors = eChecks.TableEditChecks(Global.BL.getSale(),
                                                 sList,
                                                 ctList,
                                                 tList,
                                                 sgList);

            if (errors == -1)
            {
                //  no measured trees detected in the cruise.  critical errpor stops the program.
                Close();
                return;
            }   //  endif
            errors = eChecks.MethodChecks();
            if (errors == -1)
            {
                //  empty stratum detected and user wants to quit
                Close();
                return;
            }   //  endif
            //  just check the ErrorLog table for entries
            List <ErrorLogDO> errList = Global.BL.getErrorMessages("E", "CruiseProcessing").ToList();

            if (errList.Count > 0)
            {
                ErrorReport er = new ErrorReport();
                er.fileName    = fileName;
                outputFileName = er.PrintErrorReport(errList);
                string outputMessage = "ERRORS FOUND!\nCorrect data and rerun\nOutput file is:" + outputFileName;
                MessageBox.Show(outputMessage, "ERRORS", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //  request made to open error report in preview -- May 2015
                PrintPreview pp = new PrintPreview();
                pp.fileName = outputFileName;
                pp.setupDialog();
                pp.ShowDialog();
                Environment.Exit(0);
            }   //  endif report needed

            //  Show editCheck message -- edit checks complete
            editCheck.Enabled = true;

            //  next show preparation of data
            processingStatus.Text = "Preparing data for processing.";
            processingStatus.Refresh();

            //  before making IDs, need to check for blank or null secondary products in sample groups
            //  if blank, default to 02 for every region but 6 where it will be 08 instead
            //  put a warning message in the error log table indicating the secondary product was set to a default
            //  June 2013
            string currRegion = Global.BL.getRegion();

            DefaultSecondaryProduct(currRegion);

            CalculatedValues calcVal = new CalculatedValues();


            //  retrieve lists needed and sets up population IDs
            calcVal.fileName = fileName;
            //List<TreeCalculatedValuesDO> tcvList = Global.BL.getTreeCalculatedValues();
            //List<TreeDefaultValueDO> tdvList = Global.BL.getTreeDefaults();
            List <CuttingUnitDO> cuList  = Global.BL.getCuttingUnits().ToList();
            List <LCDDO>         lcdList = Global.BL.getLCD().ToList();
            List <POPDO>         popList = Global.BL.getPOP().ToList();
            List <PRODO>         proList = Global.BL.getPRO().ToList();
            List <PlotDO>        pList   = Global.BL.getPlots().ToList();

            //List<VolumeEquationDO> vqList = Global.BL.getVolumeEquations();

            calcVal.ClearCalculatedTables();

            calcVal.MakePopulationIDs(sgList);
            //  now need some other tables to start summing values
            List <PlotDO> justPlots;

            //  show preparation of data is complete
            prepareCheck.Enabled = true;
            //  now loop through strata and show status message updating for each stratum
            StringBuilder sb = new StringBuilder();

            foreach (StratumDO sdo in sList)
            {
                CalculateTreeValues calcTreeVal = new CalculateTreeValues();
                //  update status message for next stratum
                sb.Remove(0, sb.Length);
                sb.Append("Calculating stratum ");
                sb.Append(sdo.Code);
                processingStatus.Text = sb.ToString();
                processingStatus.Refresh();

                //  Sum counts and KPI for LCD table
                justPlots = PlotMethods.GetStrata(pList, sdo.Code).ToList();
                //  need cut and leave trees for this
                //List<LCDDO> justCurrentLCD = LCDmethods.GetStratum(lcdList, sdo.Code);
                calcVal.SumTreeCountsLCD(sdo.Code, ctList, justPlots, sdo.Method, lcdList);

                //  Sum counts and KPI for POP table
                // List<POPDO> justCurrentPOP = POPmethods.GetStratumData(popList, sdo.Code, "");
                calcVal.SumTreeCountsPOP(sdo.Code, ctList, justPlots, sdo.Method, popList);

                //  Sum counts and KPI for PRO table
                // List<PRODO> justCurrentPRO = Global.BL.getPRO(sdo.Code);
                calcVal.SumTreeCountsPRO(sdo.Code, (long)sdo.Stratum_CN, tList, cuList, ctList, sgList, justPlots, proList, sdo.Method);

                //  Calculate expansion factor
                calcVal.CalcExpFac(sdo, justPlots, popList);

                //  Calculate volumes
                //calcTreeVal.fileName = fileName;
                calcTreeVal.ProcessTrees(saleList, tList, Global.BL.getVolumeEquations(), sdo.Code, sdo.Method, (long)sdo.Stratum_CN);


                //  Update 3P tally
                //List<TreeDO> justCurrentStratum = Global.BL.getTreeStratum((long)sdo.Stratum_CN);

                if (sdo.Method == "3P")
                {
                    Update3Ptally(ctList, sdo.Code, lcdList);
                }   //  endif method is 3P


                //  Update expansion factors for methods 3PPNT, F3P, and P3P
                if (sdo.Method == "3PPNT" || sdo.Method == "F3P" || sdo.Method == "P3P")
                {
                    //List<TreeCalculatedValuesDO> tcvList = Global.BL.getTreeCalculatedValues((int)sdo.Stratum_CN);
                    UpdateExpansionFactors(Global.BL.getTreeCalculatedValues(), (long)sdo.Stratum_CN);
                    //  Save update
                }   //  endif on method

                //  Sum data for the LCD, POP and PRO table
                SumAll sall = new SumAll();
                sall.fileName = fileName;
                sall.SumAllValues(sdo.Code, sdo.Method, (long)sdo.Stratum_CN, sList, pList, lcdList,
                                  popList, proList);
                Global.BL.SavePOP(popList);
                Global.BL.SavePRO(proList);
                Global.BL.SaveLCD(lcdList);

                //  Update STR tally after expansion factors are summed
                if (sdo.Method == "STR")
                {
                    UpdateSTRtally(fileName, sdo.Code, ctList, lcdList);
                } //  endif method is STR
            }     //  end foreach stratum

            //  show volume calculation is finished
            volumeCheck.Enabled   = true;
            processingStatus.Text = "Processing is DONE";
            processingStatus.Refresh();
            System.Threading.Thread.Sleep(5000);
            Close();
            return;
        }   //  end on_GO
Esempio n. 2
0
        private void on_GO(object sender, EventArgs e)
        {
            processingStatus.Text = "READY TO BEGIN?  Click GO.";
            Cursor.Current        = Cursors.WaitCursor;
            //  perform edit checks --
            processingStatus.Text = "Edit checking the data.  Please wait.";
            processingStatus.Refresh();
            //  calls edit check routines

            /*            string outputFileName;
             *          //  check for errors from FScruiser before running edit checks
             *          //  generate an error report
             *          //  June 2013
             *          List<ErrorLogDO> fscList = bslyr.getErrorMessages("E", "FScruiser");
             *          if (fscList.Count > 0)
             *          {
             *              ErrorReport eRpt = new ErrorReport();
             *              eRpt.fileName = fileName;
             *              eRpt.bslyr.fileName = bslyr.fileName;
             *              eRpt.bslyr.DAL = bslyr.DAL;
             *              outputFileName = eRpt.PrintFScruiserErrors(fscList);
             *              string outputMessage = "ERRORS FROM FSCRUISER FOUND!\nCorrect data and rerun\nOutput file is:" + outputFileName;
             *              MessageBox.Show(outputMessage, "ERRORS", MessageBoxButtons.OK, MessageBoxIcon.Stop);
             *              //  request made to open error report in preview -- May 2015
             *              PrintPreview pp = new PrintPreview();
             *              pp.fileName = outputFileName;
             *              pp.setupDialog();
             *              pp.ShowDialog();
             *              Environment.Exit(0);
             *          }   //  endif report needed
             *
             *          //  clear out error log table for just CruiseProcessing before performing checks
             *          bslyr.DeleteErrorMessages();
             *
             *          EditChecks eChecks = new EditChecks();
             *          eChecks.fileName = fileName;
             *          eChecks.bslyr.fileName = bslyr.fileName;
             *          eChecks.bslyr.DAL = bslyr.DAL;
             *
             *          int errors = eChecks.TableEditChecks();
             *          if (errors == -1)
             *          {
             *              //  no measured trees detected in the cruise.  critical errpor stops the program.
             *              Close();
             *              return;
             *          }   //  endif
             *          errors = eChecks.MethodChecks();
             *          if (errors == -1)
             *          {
             *              //  empty stratum detected and user wants to quit
             *              Close();
             *              return;
             *          }   //  endif
             *          //  just check the ErrorLog table for entries
             *          List<ErrorLogDO> errList = bslyr.getErrorMessages("E", "CruiseProcessing");
             *          if (errList.Count > 0)
             *          {
             *              ErrorReport er = new ErrorReport();
             *              er.fileName = fileName;
             *              er.bslyr.fileName = fileName;
             *              er.bslyr.DAL = bslyr.DAL;
             *              outputFileName = er.PrintErrorReport(errList);
             *              string outputMessage = "ERRORS FOUND!\nCorrect data and rerun\nOutput file is:" + outputFileName;
             *              MessageBox.Show(outputMessage, "ERRORS", MessageBoxButtons.OK, MessageBoxIcon.Stop);
             *              //  request made to open error report in preview -- May 2015
             *              PrintPreview pp = new PrintPreview();
             *              pp.fileName = outputFileName;
             *              pp.setupDialog();
             *              pp.ShowDialog();
             *              Environment.Exit(0);
             *          }   //  endif report needed
             * moved to EditCheck routine*/
            //  Show editCheck message -- edit checks complete

            EditChecks eChecks = new EditChecks();

            eChecks.fileName = fileName;
            eChecks.DAL      = DAL;

            int err = eChecks.CheckErrors();

            if (err < 0)
            {
                Close();
                return;
            }

            editCheck.Enabled = true;

            //  next show preparation of data
            processingStatus.Text = "Preparing data for processing.";
            processingStatus.Refresh();

            //  before making IDs, need to check for blank or null secondary products in sample groups
            //  if blank, default to 02 for every region but 6 where it will be 08 instead
            //  put a warning message in the error log table indicating the secondary product was set to a default
            //  June 2013
            List <SaleDO> saleList = new List <SaleDO>();

            saleList = DAL.From <SaleDO>().Read().ToList();
            string currRegion = saleList[0].Region;

            //string currRegion = bslyr.getRegion();

            DefaultSecondaryProduct(currRegion);

            CalculateTreeValues calcTreeVal = new CalculateTreeValues();
            CalculatedValues    calcVal     = new CalculatedValues();


            //  retrieve lists needed and sets up population IDs
            calcVal.fileName = fileName;
            calcVal.DAL      = DAL;
            //   List<SampleGroupDO> sgList = bslyr.getSampleGroups();
            //   List<TreeDefaultValueDO> tdvList = bslyr.getTreeDefaults();
            //   List<CountTreeDO> ctList = bslyr.getCountTrees();
            //   List<PlotDO> pList = bslyr.getPlots();

            //   calcVal.ClearCalculatedTables();
            //   calcVal.MakePopulationIDs(sgList, tdvList);

            calcVal.CalcValues();

            CPbusinessLayer bslyr = new CPbusinessLayer();

            bslyr.DAL = DAL;
            //  now need some other tables to start summing values
            List <LCDDO>              lcdList = bslyr.getLCD();
            List <POPDO>              popList = bslyr.getPOP();
            List <PRODO>              proList = bslyr.getPRO();
            List <StratumDO>          sList   = bslyr.getStratum();
            List <SampleGroupDO>      sgList  = bslyr.getSampleGroups();
            List <TreeDefaultValueDO> tdvList = bslyr.getTreeDefaults();
            List <CountTreeDO>        ctList  = bslyr.getCountTrees();
            List <PlotDO>             pList   = bslyr.getPlots();
            List <TreeDO>             tList   = bslyr.getTrees();

            calcTreeVal.fileName       = fileName;
            calcTreeVal.bslyr.fileName = fileName;
            calcTreeVal.bslyr.DAL      = bslyr.DAL;

            //  show preparation of data is complete
            prepareCheck.Enabled = true;
            //  now loop through strata and show status message updating for each stratum
            StringBuilder sb = new StringBuilder();

            foreach (StratumDO sdo in sList)
            {
                //  update status message for next stratum
                sb.Clear();
                sb.Append("Calculating stratum ");
                sb.Append(sdo.Code);
                processingStatus.Text = sb.ToString();
                processingStatus.Refresh();

                //  Sum counts and KPI for LCD table
                List <PlotDO> justPlots = PlotMethods.GetStrata(pList, sdo.Code);
                //  need cut and leave trees for this
                List <LCDDO> justCurrentLCD = LCDmethods.GetStratum(lcdList, sdo.Code);
                calcVal.SumTreeCountsLCD(sdo.Code, ctList, justPlots, justCurrentLCD, sdo.Method, lcdList);

                //  Sum counts and KPI for POP table
                List <POPDO> justCurrentPOP = POPmethods.GetStratumData(popList, sdo.Code, "");
                calcVal.SumTreeCountsPOP(sdo.Code, ctList, justPlots, justCurrentPOP, sdo.Method, popList);

                //  Sum counts and KPI for PRO table
                List <PRODO> justCurrentPRO = PROmethods.GetCutTrees(proList, sdo.Code, "", "", 0);
                calcVal.SumTreeCountsPRO(sdo.Code, ctList, justPlots, justCurrentPRO, sdo.Method, proList);

                //  Calculate expansion factor
                calcVal.CalcExpFac(sdo, justPlots, justCurrentPOP);

                //  Calculate volumes
                calcTreeVal.ProcessTrees(sdo.Code, sdo.Method, (long)sdo.Stratum_CN);

                //  Update 3P tally
                if (sdo.Method == "3P")
                {
                    List <LCDDO> LCDstratum = LCDmethods.GetStratumGroupedBy(fileName, sdo.Code, bslyr);

                    Update3Ptally(fileName, ctList, justCurrentLCD, tList, LCDstratum);
                    //  Save
                    bslyr.SaveLCD(justCurrentLCD);
                }   //  endif method is 3P


                //  Update expansion factors for methods 3PPNT, F3P, and P3P
                if (sdo.Method == "3PPNT" || sdo.Method == "F3P" || sdo.Method == "P3P")
                {
                    List <TreeDO> justCurrentStratum = tList.FindAll(
                        delegate(TreeDO td)
                    {
                        return(td.Stratum.Code == sdo.Code);
                    });
                    List <TreeCalculatedValuesDO> tcvList = bslyr.getTreeCalculatedValues((int)sdo.Stratum_CN);
                    UpdateExpansionFactors(justCurrentStratum, tcvList);
                    //  Save update
                    bslyr.SaveTrees(justCurrentStratum);
                }   //  endif on method

                //  Sum data for the LCD, POP and PRO table
                SumAll Sml = new SumAll();
                Sml.fileName       = fileName;
                Sml.bslyr.fileName = bslyr.fileName;
                Sml.bslyr.DAL      = bslyr.DAL;
                Sml.SumAllValues(sdo.Code, sdo.Method, (int)sdo.Stratum_CN, sList, pList, justCurrentLCD,
                                 justCurrentPOP, justCurrentPRO);

                //  Update STR tally after expansion factors are summed
                if (sdo.Method == "STR")
                {
                    UpdateSTRtally(fileName, sdo.Code, justCurrentLCD, ctList, lcdList);
                    //  save
                    bslyr.SaveLCD(lcdList);
                } //  endif method is STR
            }     //  end foreach stratum

            //  show volume calculation is finished
            volumeCheck.Enabled   = true;
            processingStatus.Text = "Processing is DONE";
            processingStatus.Refresh();
            System.Threading.Thread.Sleep(5000);
            Cursor.Current = this.Cursor;

            Close();
            return;
        }   //  end on_GO