public void createGraphs() { List <TreeDO> tList = bslyr.getTrees(); List <LCDDO> lcdList = bslyr.getLCD(); List <StratumDO> sList = bslyr.getStratum(); List <LCDDO> justSpecies = bslyr.getLCDOrdered("WHERE CutLeave = @p1 ", "GROUP BY Species", "C", ""); // pull salename and number to put in graph title // also need it to create subfolder for graphs List <SaleDO> saleList = bslyr.getSale(); string currSaleName = saleList[0].Name; if (currSaleName.Length > 25) { currSaleName = currSaleName.Remove(25, currSaleName.Length); } string currSaleNumber = saleList[0].SaleNumber; // pull data needed and call appropriate graph routine for report switch (currentReport) { case "GR01": foreach (LCDDO js in justSpecies) { // pull all trees for each species List <TreeDO> justTrees = tList.FindAll( delegate(TreeDO td) { return(td.Species == js.Species && td.CountOrMeasure == "M"); }); currTitle.Append("DBH AND TOTAL HEIGHT BY "); if (justTrees.Count == 0) { noDataForGraph(js.Species, "Species"); break; } else { currTitle.Append(js.Species); currTitle.Append("\nSale number: "); currTitle.Append(currSaleNumber); currTitle.Append(" Sale name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = "DBH"; gf.currYtitle = "TOTAL HEIGHT"; gf.graphNum = 1; gf.currSP = js.Species; gf.fileName = fileName; gf.chartType = "SCATTER"; gf.treeList = justTrees; gf.currSaleName = currSaleName; gf.ShowDialog(); } // endif no data currTitle.Remove(0, currTitle.Length); justTrees.Clear(); } // end foreach loop break; case "GR02": if (lcdList.Count == 0) { MessageBox.Show("No data found for report.\nTry processing the cruise again.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // endif no data // total expansion factor for each species to get data for the sale foreach (LCDDO js in justSpecies) { List <LCDDO> speciesGroup = lcdList.FindAll( delegate(LCDDO l) { return(l.Species == js.Species); }); expandData(speciesGroup, "EXPFAC", sList, js.Species); } // end foreach justSpecies currTitle.Remove(0, currTitle.Length); currTitle.Append("SPECIES DISTRIBUTION FOR THE SALE"); currTitle.Append("\nSale number: "); currTitle.Append(currSaleNumber); currTitle.Append(" Sale name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = ""; gf.currYtitle = ""; gf.graphNum = 2; gf.chartType = "PIE"; gf.lcdList = speciesTotal; gf.fileName = fileName; gf.currSaleName = currSaleName; gf.ShowDialog(); break; case "GR03": speciesTotal.Clear(); // total net CUFT volume for sawtimber only foreach (LCDDO js in justSpecies) { List <LCDDO> speciesGroup = lcdList.FindAll( delegate(LCDDO l) { return(l.Species == js.Species && l.PrimaryProduct == "01"); }); expandData(speciesGroup, "VOL", sList, js.Species); } // end foreach justSpecies currTitle.Remove(0, currTitle.Length); currTitle.Append("VOLUME BY SPECIES -- SAWTIMBER ONLY"); currTitle.Append("\nSale number: "); currTitle.Append(currSaleNumber); currTitle.Append(" Sale name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = ""; gf.currYtitle = ""; gf.graphNum = 3; gf.chartType = "PIE"; gf.lcdList = speciesTotal; gf.fileName = fileName; gf.currSaleName = currSaleName; gf.ShowDialog(); break; case "GR04": List <LCDDO> justProduct = bslyr.getLCDOrdered("WHERE CutLeave = @p1 ", "GROUP BY PrimaryProduct", "C", ""); speciesTotal.Clear(); // total net CUFT volume for sawtimber only foreach (LCDDO jp in justProduct) { List <LCDDO> productGroup = lcdList.FindAll( delegate(LCDDO l) { return(l.PrimaryProduct == jp.PrimaryProduct); }); expandData(productGroup, "VOL", sList, jp.PrimaryProduct); } // end foreach justSpecies currTitle.Remove(0, currTitle.Length); currTitle.Append("VOLUME BY PRODUCT"); currTitle.Append("\nSale number: "); currTitle.Append(currSaleNumber); currTitle.Append(" Sale name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = ""; gf.currYtitle = ""; gf.graphNum = 4; gf.chartType = "PIE"; gf.lcdList = speciesTotal; gf.fileName = fileName; gf.currSaleName = currSaleName; gf.ShowDialog(); break; case "GR05": // per request from Region 10, give option to use 16 or 32 foot logs // for this graph -- July 2017 int whichLength = 16; selectLength getLength = new selectLength(); getLength.ShowDialog(); if (getLength.lengthSelected == 0) { whichLength = 16; } else { whichLength = getLength.lengthSelected; } // pull by species for separate graphs List <LogStockDO> logsTotal = new List <LogStockDO>(); List <LogStockDO> lsList = bslyr.getLogStock(); // need to expand also foreach (LCDDO js in justSpecies) { // pull all logs List <LogStockDO> justSelectLogs = lsList.FindAll( delegate(LogStockDO lsd) { return(lsd.Length == whichLength && lsd.Tree.Species == js.Species); }); if (justSelectLogs.Count == 0) { MessageBox.Show("Graph cannot be created.\nNo logs found.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } // endif logsTotal = LoadLogs(justSelectLogs, js.Species, sList); currTitle.Remove(0, currTitle.Length); if (whichLength == 16) { currTitle.Append("NUMBER OF 16-FOOT LOGS BY DIB CLASS -- "); } else if (whichLength == 32) { currTitle.Append("NUMBER OF 32-FOOT LOGS BY DIB CLASS -- "); } currTitle.Append(js.Species); currTitle.Append("\nSale number: "); currTitle.Append(currSaleNumber); currTitle.Append(" Sale name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = "DIB CLASS"; gf.currYtitle = "NUMBER OF LOGS"; gf.graphNum = 5; gf.chartType = "BAR"; gf.logStockList = logsTotal; gf.currSP = js.Species; gf.fileName = fileName; gf.currSaleName = currSaleName; gf.ShowDialog(); } // end foreach loop on species break; case "GR06": // pull just measured and cut trees justMeasured = tList.FindAll( delegate(TreeDO td) { return(td.CountOrMeasure == "M" && td.SampleGroup.CutLeave == "C"); }); // expand data and group by DBH class expandData(justMeasured, sList); currTitle.Remove(0, currTitle.Length); currTitle.Append("DIAMETER DISTRIBUTION FOR THE SALE"); currTitle.Append("\nSale number: "); currTitle.Append(currSaleNumber); currTitle.Append(" Sale name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = "DBH"; gf.currYtitle = "NUMBER OF TREES"; gf.graphNum = 6; gf.chartType = "BAR"; gf.treeList = treesByDBH; gf.fileName = fileName; gf.currSaleName = currSaleName; gf.ShowDialog(); break; case "GR07": // need by species foreach (LCDDO js in justSpecies) { // need species, measured and cut trees justMeasured = tList.FindAll( delegate(TreeDO td) { return(td.CountOrMeasure == "M" && td.SampleGroup.CutLeave == "C" && td.Species == js.Species); }); // expand data expandData(justMeasured, sList); // load currTitle.Remove(0, currTitle.Length); currTitle.Append("DIAMETER DISTRIBUTION FOR SPECIES "); currTitle.Append(js.Species); currTitle.Append("\nSale number: "); currTitle.Append(currSaleNumber); currTitle.Append(" Sale name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = "DBH"; gf.currYtitle = "NUMBER OF TREES"; gf.graphNum = 7; gf.chartType = "BAR"; gf.treeList = treesByDBH; gf.currSP = js.Species; gf.fileName = fileName; gf.currSaleName = currSaleName; gf.ShowDialog(); treesByDBH.Clear(); } // end foreach species break; case "GR08": // need by stratum foreach (StratumDO s in sList) { // need measured and cut trees for each stratum justMeasured = tList.FindAll( delegate(TreeDO td) { return(td.CountOrMeasure == "M" && td.SampleGroup.CutLeave == "C" && td.Stratum.Code == s.Code); }); // expand data expandData(justMeasured, sList); // load currTitle.Remove(0, currTitle.Length); currTitle.Append("DIAMETER DISTRIBUTION BY STRATUM "); currTitle.Append(s.Code); currTitle.Append("\nSale number: "); currTitle.Append(currSaleNumber); currTitle.Append(" Sale name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = "DBH"; gf.currYtitle = "NUMBER OF TREES"; gf.graphNum = 8; gf.chartType = "BAR"; gf.treeList = treesByDBH; gf.currSP = s.Code; gf.fileName = fileName; gf.currSaleName = currSaleName; gf.ShowDialog(); treesByDBH.Clear(); } // end foreach stratum break; case "GR09": // need values from TreEstimate table // if that table is empty, it means no 3P strata or the file was created // prior to March 2015 when the table was implemented. List <TreeEstimateDO> treeEstimates = bslyr.getTreeEstimates(); if (treeEstimates.Count == 0) { MessageBox.Show("No estimate data is available for GR09.\nCannot produce this graph.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // endif List <TreeDO> uniqueSpecies = bslyr.GetUniqueSpecies(); List <CountTreeDO> cList = bslyr.getCountTrees(); List <CreateTextFile.ReportSubtotal> graphData = new List <CreateTextFile.ReportSubtotal>(); foreach (TreeDO u in uniqueSpecies) { // pull all tree default value for current species List <CountTreeDO> countSpecies = cList.FindAll( delegate(CountTreeDO ct) { return(ct.TreeDefaultValue_CN == u.TreeDefaultValue_CN); }); // accumulate all count tree cn in TreeEstimate for this species foreach (CountTreeDO c in countSpecies) { List <TreeEstimateDO> justEst = treeEstimates.FindAll( delegate(TreeEstimateDO te) { return(te.CountTree_CN == c.CountTree_CN); }); if (justEst.Count > 0) { buildKPIdata(justEst, graphData); } } // end foreach loop // reset categories based on Ken's logic List <CreateTextFile.ReportSubtotal> categoryData = new List <CreateTextFile.ReportSubtotal>(); if (graphData.Count > 0) { resetCategories(graphData, categoryData); // load currTitle.Remove(0, currTitle.Length); currTitle.Append("KPI DISTRIBUTION BY SPECIES -- "); currTitle.Append(u.Species); currTitle.Append("\nSale number: "); currTitle.Append(currSaleNumber); currTitle.Append(" Sale name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = "KPI"; gf.currYtitle = "NUMBER OF TREES"; gf.graphNum = 9; gf.chartType = "BAR"; gf.graphData = categoryData; gf.currSP = u.Species; gf.fileName = fileName; gf.currSaleName = currSaleName; gf.ShowDialog(); graphData.Clear(); categoryData.Clear(); } // endif } // end foreach loop break; case "GR10": List <CreateTextFile.ReportSubtotal> dataToGraph = new List <CreateTextFile.ReportSubtotal>(); // need to loop by stratum foreach (StratumDO s in sList) { if (s.BasalAreaFactor > 0) { // Pull plots for this stratum List <PlotDO> pList = bslyr.GetStrataPlots(s.Code); double numplots = pList.Count; // Pull tree data for this stratum List <TreeDO> treeList = bslyr.getTrees(); // Pull stratum from LCD to get species in the stratum List <LCDDO> lList = bslyr.getLCD(); List <LCDDO> justStratum = lList.FindAll( delegate(LCDDO ld) { return(ld.Stratum == s.Code); }); // Then find number of trees for the stratum and each species in the stratum foreach (LCDDO js in justStratum) { List <TreeDO> justTrees = treeList.FindAll( delegate(TreeDO td) { return(td.Stratum.Code == s.Code && td.Species == js.Species && td.SampleGroup.CutLeave == "C" && td.LiveDead == js.LiveDead); }); // Load into graphData -- see if species is already in the list int nthRow = dataToGraph.FindIndex( delegate(CreateTextFile.ReportSubtotal cr) { return(cr.Value1 == js.Species); }); if (nthRow < 0) { CreateTextFile.ReportSubtotal rs = new CreateTextFile.ReportSubtotal(); rs.Value1 = js.Species; rs.Value3 = (s.BasalAreaFactor * justTrees.Count) / numplots; dataToGraph.Add(rs); } else if (nthRow >= 0) { dataToGraph[nthRow].Value3 += (s.BasalAreaFactor * justTrees.Count) / numplots; } // endif } // end foreach loop // load graphData if (dataToGraph.Count > 0) { currTitle.Remove(0, currTitle.Length); currTitle.Append("BAF PER ACRE BY SPECIES FOR STRATUM "); currTitle.Append(s.Code); currTitle.Append("\nSale Number: "); currTitle.Append(currSaleNumber); currTitle.Append("\n"); currTitle.Append(" Sale Name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = ""; gf.currYtitle = ""; gf.graphNum = 10; gf.chartType = "PIE"; gf.currSP = s.Code; gf.graphData = dataToGraph; gf.fileName = fileName; gf.currSaleName = currSaleName; gf.ShowDialog(); dataToGraph.Clear(); } // endif } // endif on basal area factor } // end foreach loop on stratum break; case "GR11": // pull data by sample group List <SampleGroupDO> sgList = bslyr.getSampleGroups(); float numPlots = 0; // find all trees for each group foreach (SampleGroupDO sg in sgList) { if (sg.Stratum.BasalAreaFactor > 0) { // find all strata for this group in LCD List <LCDDO> lList = bslyr.getLCD(); List <LCDDO> justStrata = lList.FindAll( delegate(LCDDO l) { return(l.SampleGroup == sg.Code); }); // find number of plots for the strata string currST = "*"; foreach (LCDDO js in justStrata) { if (currST != js.Stratum) { List <PlotDO> pList = bslyr.GetStrataPlots(js.Stratum); numPlots += pList.Count(); currST = js.Stratum; } // endif } // end foreach loop // now find all trees for the sample group justMeasured = tList.FindAll( delegate(TreeDO td) { return(td.SampleGroup_CN == sg.SampleGroup_CN && td.CountOrMeasure == "M" && td.SampleGroup.CutLeave == "C" && td.Stratum_CN == sg.Stratum_CN); }); // load DIB classes LoadDIBclass(justMeasured); // Accumulate number of trees for each class foreach (TreeDO jm in justMeasured) { // find class to update int nthRow = findDIBindex(treesByDBH, jm.DBH); if (nthRow >= 0) { treesByDBH[nthRow].TreeCount++; } } // end foreach loop // Calculate foreach (TreeDO tbd in treesByDBH) { // Calculate value for each DIB class tbd.TreeCount = (float)((sg.Stratum.BasalAreaFactor * tbd.TreeCount) / numPlots); } // end foreach loop // load dat6a for gtraph currTitle.Remove(0, currTitle.Length); currTitle.Append("BAF PER ACRE FOR SAMPLE GROUP "); currTitle.Append(sg.Code); currTitle.Append("\nSaleNumber: "); currTitle.Append(currSaleNumber); currTitle.Append("\nSale name: "); currTitle.Append(currSaleName); gf.currTitle = currTitle.ToString(); gf.currXtitle = "DBH Class"; gf.currYtitle = "Basal Area Factor"; gf.graphNum = 11; gf.chartType = "BAR"; gf.currSP = sg.Code; gf.treeList = treesByDBH; gf.fileName = fileName; gf.currSaleName = currSaleName; gf.ShowDialog(); } // endif } // end foreach loop break; } // end switch on report return; } // end createGraphs