} // end ClearCalculatedTables public void MakePopulationIDs(List <SampleGroupDO> sgList, List <TreeDefaultValueDO> tdvList) { CPbusinessLayer bslyr = new CPbusinessLayer(); bslyr.DAL = DAL; bslyr.fileName = fileName; // Load ID info into tables List <LCDDO> lcdList = new List <LCDDO>(); List <POPDO> popList = new List <POPDO>(); List <PRODO> proList = new List <PRODO>(); List <TreeDO> tList = bslyr.getTrees(); // need to check Contract Species in TDV table before doing unique // reset to a blank if it is null -- September 2016 List <TreeDefaultValueDO> treeDefaults = bslyr.getTreeDefaults(); foreach (TreeDefaultValueDO tdv in treeDefaults) { if (tdv.ContractSpecies == null) { tdv.ContractSpecies = " "; } else if (tdv.ContractSpecies == "") { tdv.ContractSpecies = " "; } } // end foreach bslyr.SaveTreeDefaults(treeDefaults); foreach (SampleGroupDO sgd in sgList) { // Load LCD population IDs // Need unique species, livedead and grade from Tree table // not sure about the count table -- need IDs from there? 11/2012 List <TreeDO> distinctSpecies = bslyr.GetDistinctSpecies((long)sgd.SampleGroup_CN); foreach (TreeDO t in distinctSpecies) { LCDDO lcd = new LCDDO(); lcd.CutLeave = sgd.CutLeave; lcd.Stratum = sgd.Stratum.Code; lcd.SampleGroup = sgd.Code; lcd.PrimaryProduct = sgd.PrimaryProduct; lcd.SecondaryProduct = sgd.SecondaryProduct; lcd.UOM = sgd.UOM; lcd.Species = t.Species; lcd.LiveDead = t.LiveDead; if (t.Grade == null) { lcd.TreeGrade = ""; } else { lcd.TreeGrade = t.Grade; } lcd.STM = t.STM; // per K.Cormier, because a null value in contract species causes // causes problems, it is being dropped from the population ID for LCD // Howeverm it will be stored as null but not used as part of the ID // September 2016 // Found a slicker way to address this -- default contract species to a blank // however, this would be in the TreeDefaultValue table and only affects // new cruises. CP still needs to set CS in TDV to blank (see above). lcd.ContractSpecies = t.TreeDefaultValue.ContractSpecies; //if (t.TreeDefaultValue.ContractSpecies != null) // lcd.ContractSpecies = t.TreeDefaultValue.ContractSpecies; //else lcd.ContractSpecies = ""; if (t.Stratum.YieldComponent != null) { lcd.Yield = t.Stratum.YieldComponent; } else { lcd.Yield = ""; } //} // endif nthRow lcdList.Add(lcd); } // end foreach loop on species // Load POP population IDs POPDO pop = new POPDO(); // Don't need unique species for this group pop.CutLeave = sgd.CutLeave; pop.Stratum = sgd.Stratum.Code; pop.SampleGroup = sgd.Code; pop.PrimaryProduct = sgd.PrimaryProduct; pop.SecondaryProduct = sgd.SecondaryProduct; pop.UOM = sgd.UOM; // check for sure-to-measure trees for this group // Add non-sure-to-measure first and then STM pop.STM = "N"; popList.Add(pop); List <TreeDO> justSTM = tList.FindAll( delegate(TreeDO td) { return(sgd.CutLeave == td.SampleGroup.CutLeave && sgd.Stratum.Code == td.Stratum.Code && sgd.Code == td.SampleGroup.Code && sgd.PrimaryProduct == td.SampleGroup.PrimaryProduct && sgd.SecondaryProduct == td.SampleGroup.SecondaryProduct && sgd.UOM == td.SampleGroup.UOM && td.STM == "Y"); }); if (justSTM.Count > 0) { POPDO popSTM = new POPDO(); popSTM.CutLeave = sgd.CutLeave; popSTM.Stratum = sgd.Stratum.Code; popSTM.SampleGroup = sgd.Code; popSTM.PrimaryProduct = sgd.PrimaryProduct; popSTM.SecondaryProduct = sgd.SecondaryProduct; popSTM.UOM = sgd.UOM; popSTM.STM = "Y"; popList.Add(popSTM); } // endif // Load PRO population IDs // These need cutting unit numbers -- from Cutting Unit List <CuttingUnitStratumDO> strataUnits = bslyr.getCuttingUnitStratum((long)sgd.Stratum_CN); foreach (CuttingUnitStratumDO cudo in strataUnits) { PRODO pro = new PRODO(); pro.CutLeave = sgd.CutLeave; pro.Stratum = sgd.Stratum.Code; pro.CuttingUnit = cudo.CuttingUnit.Code; pro.SampleGroup = sgd.Code; pro.PrimaryProduct = sgd.PrimaryProduct; pro.SecondaryProduct = sgd.SecondaryProduct; pro.UOM = sgd.UOM; // check for sure-to-measure trees for this group // Add non-sure-to-measure first and then STM pro.STM = "N"; proList.Add(pro); justSTM = tList.FindAll( delegate(TreeDO td) { return(sgd.CutLeave == td.SampleGroup.CutLeave && sgd.Stratum.Code == td.Stratum.Code && cudo.CuttingUnit.Code == td.CuttingUnit.Code && sgd.Code == td.SampleGroup.Code && sgd.PrimaryProduct == td.SampleGroup.PrimaryProduct && sgd.SecondaryProduct == td.SampleGroup.SecondaryProduct && sgd.UOM == td.SampleGroup.UOM && td.STM == "Y"); }); if (justSTM.Count > 0) { PRODO proSTM = new PRODO(); proSTM.CutLeave = sgd.CutLeave; proSTM.Stratum = sgd.Stratum.Code; proSTM.CuttingUnit = cudo.CuttingUnit.Code; proSTM.SampleGroup = sgd.Code; proSTM.PrimaryProduct = sgd.PrimaryProduct; proSTM.SecondaryProduct = sgd.SecondaryProduct; proSTM.UOM = sgd.UOM; proSTM.STM = "Y"; proList.Add(proSTM); } // endif } // end foreach loop on strataUnits } // end foreach loop on SampleGroup bslyr.SaveLCD(lcdList); bslyr.SavePOP(popList); bslyr.SavePRO(proList); return; } // end MakePopulationIDs