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
} // end SumTreeCountsPRO public void CalcExpFac(StratumDO sdo, List <PlotDO> justPlots, List <POPDO> justCurrentPOP) { CPbusinessLayer bslyr = new CPbusinessLayer(); bslyr.DAL = DAL; bslyr.fileName = fileName; // Calculates expansion factor, tree factor and point factor for each tree in the current population double EF = 0.0; // expansion factor double TF = 0.0; // tree factor double PF = 0.0; // point factor // Need total number of plots and measured plots (3PPNT only) double totalPlots = justPlots.Count(); double totalMeasPlots = 0.0; // process by population foreach (POPDO pdo in justCurrentPOP) { // pull trees for population List <TreeDO> justTrees = new List <TreeDO>(); if (sdo.Method == "FIXCNT") { justTrees = bslyr.getPOPtrees(pdo, "C"); } else { justTrees = bslyr.getPOPtrees(pdo, "M"); } // 3PPNT uses measured plots if (sdo.Method == "3PPNT") { foreach (PlotDO p in justPlots) { int nthRow = justTrees.FindIndex( delegate(TreeDO td) { return(td.Plot_CN == p.Plot_CN && td.Stratum_CN == p.Stratum_CN); }); if (nthRow >= 0) { totalMeasPlots++; } } // end foreach loop } // endif Method is 3PPNT // calculate factors on each tree foreach (TreeDO tdo in justTrees) { // Calculate point factor for P3P S3P F3P PCM FCM and 3PPNT switch (sdo.Method) { case "P3P": case "S3P": case "F3P": PF = CommonEquations.Frequency3P(pdo.SumKPI, tdo.KPI, pdo.MeasuredTrees); break; case "PCM": case "PCMTRE": PF = CommonEquations.CalcTreeFactor(pdo.FirstStageTrees, pdo.MeasuredTrees, 0.0, 1, 2); break; case "FCM": PF = CommonEquations.CalcTreeFactor(0.0, pdo.MeasuredTrees, pdo.TalliedTrees, 3, 2); break; case "3PPNT": // uses plot KPI PlotDO plotKPI = justPlots.Find( delegate(PlotDO p) { return(p.Plot_CN == tdo.Plot_CN); }); PF = CommonEquations.Frequency3P(pdo.SumKPI, plotKPI.KPI, totalMeasPlots); break; } // end switch on method to calculate point factor // Calculate tree factor for FIXCNT FIX F3P FCM PNT P3P PCM 3PPNT and S3P switch (sdo.Method) { case "FIXCNT": case "FIX": case "F3P": TF = sdo.FixedPlotSize; break; case "FCM": if (totalPlots > 0) { TF = sdo.FixedPlotSize / totalPlots; } break; case "PNT": case "P3P": case "PCM": case "PCMTRE": case "3PPNT": if (tdo.DBH > 0) { TF = CommonEquations.PointSampleFrequency(sdo.BasalAreaFactor, tdo.DBH); } else if (tdo.DRC > 0) { TF = CommonEquations.PointSampleFrequency(sdo.BasalAreaFactor, tdo.DRC); } break; case "S3P": TF = CommonEquations.CalcTreeFactor(pdo.FirstStageTrees, 0.0, pdo.TalliedTrees, 3, 1); break; } // end switch on method to calculate tree factor // Calculate expansion factor switch (sdo.Method) { case "100": EF = 1.0; break; case "FIXCNT": if (totalPlots > 0) { EF = (sdo.FixedPlotSize / totalPlots) * tdo.TreeCount; } break; case "FIX": if (totalPlots > 0) { EF = sdo.FixedPlotSize / totalPlots; } break; case "PNT": if (totalPlots > 0) { EF = TF / totalPlots; } break; case "STR": EF = CommonEquations.CalcTreeFactor(0.0, pdo.MeasuredTrees, pdo.TalliedTrees, 3, 2); break; case "P3P": case "F3P": case "PCM": case "PCMTRE": case "3PPNT": if (totalPlots > 0) { EF = (TF * PF) / totalPlots; } break; case "FCM": case "S3P": EF = TF * PF; break; case "3P": EF = CommonEquations.Frequency3P(pdo.SumKPI, tdo.KPI, pdo.MeasuredTrees); break; } // end switch on method to calculate expansion factor if (tdo.STM == "Y") { EF = 1.0; } // round just the expansion factor EF = CommonEquations.RoundExpansionFactor(EF); // store factors tdo.ExpansionFactor = (float)EF; tdo.TreeFactor = (float)TF; tdo.PointFactor = (float)PF; } // end foreach loop on justTrees // save this bunch of trees bslyr.SaveTrees(justTrees); } // end foreach loop on justCurrentPOP return; } // end CalcExpFac