Exemplo n.º 1
0
        }   //  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
Exemplo n.º 2
0
        }   //  end SumTreeCountsPOP

        public void SumTreeCountsPRO(string currST, List <CountTreeDO> ctList, List <PlotDO> justPlots, List <PRODO> justCurrentPRO, string currMethod, List <PRODO> proList)
        {
            CPbusinessLayer bslyr = new CPbusinessLayer();

            bslyr.DAL      = DAL;
            bslyr.fileName = fileName;
            //  Sums tree counts from either the Count Tree table or tree count records
            foreach (PRODO pro in justCurrentPRO)
            {
                firstSum         = 0.0;
                talliedSum       = 0.0;
                totalKPI         = 0.0;
                totalMeasuredKPI = 0.0;
                //  find measured trees for current PRO group
                List <TreeDO> proTrees = bslyr.getPROtrees(pro, "M");
                //  measured trees is just a count of the trees for current PRO group
                pro.MeasuredTrees = proTrees.Count();

                //  now need count trees from tree count records
                List <TreeDO> proCntTrees = bslyr.getPROtrees(pro, "C");
                //  Sum all tree counts for first stage and total tallied
                //  see note in POP or LCD section on 100% method
                if (currMethod == "STR" || currMethod == "100")
                {
                    firstSum = proTrees.Count();
                }
                else if (currMethod != "3P")
                {
                    firstSum  = proTrees.Sum(tdo => tdo.TreeCount);
                    firstSum += proCntTrees.Sum(tdo => tdo.TreeCount);
                }

                if (pro.STM == "Y")
                {
                    firstSum   += pro.MeasuredTrees;
                    talliedSum += pro.MeasuredTrees;
                    //talliedSum = proTrees.Sum(tdo => tdo.TreeCount);
                }
                else
                {
                    //if (currMethod == "3P" || currMethod == "100")
                    if (currMethod == "100")
                    {
                        talliedSum += pro.MeasuredTrees;
                    }
                    else
                    {
                        talliedSum  = proTrees.Sum(tdo => tdo.TreeCount);
                        talliedSum += proCntTrees.Sum(tdo => tdo.TreeCount);
                    } //  endif on current method
                }     //  endif
                //  insurance trees go into just the tallied tree count
                List <TreeDO> lcdInsurance = bslyr.getPROtrees(pro, "I");
                talliedSum += lcdInsurance.Sum(tdo => tdo.TreeCount);
                //  Complete totals and KPIs based on method
                List <CountTreeDO> proCountCounts = new List <CountTreeDO>();
                switch (currMethod)
                {
                case "3P":
                case "S3P":
                    proCountCounts = ctList.FindAll(
                        delegate(CountTreeDO ctd)
                    {
                        return(pro.CutLeave == ctd.SampleGroup.CutLeave &&
                               pro.Stratum == ctd.SampleGroup.Stratum.Code &&
                               pro.SampleGroup == ctd.SampleGroup.Code &&
                               pro.CuttingUnit == ctd.CuttingUnit.Code &&
                               pro.PrimaryProduct == ctd.SampleGroup.PrimaryProduct &&
                               pro.SecondaryProduct == ctd.SampleGroup.SecondaryProduct &&
                               pro.UOM == ctd.SampleGroup.UOM);
                    });
                    if (pro.STM == "N")
                    {
                        firstSum   += pro.MeasuredTrees;
                        talliedSum += proCountCounts.Sum(ctd => ctd.TreeCount);
                        totalKPI   += proCountCounts.Sum(ctd => ctd.SumKPI);
                    }
                    //  Sum measured KPI from trees
                    totalMeasuredKPI = proTrees.Sum(tdo => tdo.KPI);
                    //  for S3P, sum of KPI is total of count and measured KPI from the trees == November 2013
                    //  even though individual KPI may be zero for either method
                    //  however, countTree has sum of count and measured KPI for 3P so adding measured and count
                    //  from trees will double count for 3P ONLY -- December 2013
                    if (currMethod == "S3P")
                    {
                        totalKPI += proCntTrees.Sum(lc => lc.KPI);
                        totalKPI += proTrees.Sum(lt => lt.KPI);
                    }       //  endif on current method
                    break;

                case "STR":
                    proCountCounts = ctList.FindAll(
                        delegate(CountTreeDO ctd)
                    {
                        return(pro.CutLeave == ctd.SampleGroup.CutLeave &&
                               pro.Stratum == ctd.SampleGroup.Stratum.Code &&
                               pro.SampleGroup == ctd.SampleGroup.Code &&
                               pro.CuttingUnit == ctd.CuttingUnit.Code &&
                               pro.PrimaryProduct == ctd.SampleGroup.PrimaryProduct &&
                               pro.SecondaryProduct == ctd.SampleGroup.SecondaryProduct &&
                               pro.UOM == ctd.SampleGroup.UOM);
                    });
                    talliedSum += proCountCounts.Sum(ctd => ctd.TreeCount);
                    break;

                case "F3P":
                case "P3P":
                    //  Sum measured KPI from trees
                    totalMeasuredKPI = proTrees.Sum(tdo => tdo.KPI);
                    totalKPI         = proCntTrees.Sum(tdo => tdo.KPI);
                    totalKPI        += totalMeasuredKPI;
                    totalKPI        += proCountCounts.Sum(ctd => ctd.SumKPI);
                    break;

                case "3PPNT":
                    //  this will probably no longer work on legacy data until
                    //  the conversion program handles this change
                    if (proTrees.Count > 0)
                    {
                        //  means there are measured trees so this was a measured plot
                        //  KPI in the plot table is measured
                        totalMeasuredKPI = justPlots.Sum(pd => pd.KPI);
                        //  plus add to total KPI
                        totalKPI = justPlots.Sum(pd => pd.KPI);
                    }
                    else
                    {
                        //  no measured trees means this is a count plot
                        //  just add plot KPI to total KPI
                        totalKPI += justPlots.Sum(pd => pd.KPI);
                    }       //  endif
                    //  this piece of code will no longer work -- September 2013
                    //totalMeasuredKPI = lcdTrees.Sum(tdo => tdo.KPI);
                    //totalKPI += lcdCountCounts.Sum(ctd => ctd.SumKPI);
                    //  Add plot KPI to total KPI
                    //totalKPI += justPlots.Sum(pd => pd.KPI);
                    //  Sum measured KPI from trees
                    //totalMeasuredKPI = proTrees.Sum(tdo => tdo.KPI);
                    //totalKPI += proCountCounts.Sum(ctd => ctd.SumKPI);
                    //  Add plot KPI to total KPI
                    //totalKPI += justPlots.Sum(pd => pd.KPI);
                    break;
                }   //  end switch on method

                pro.FirstStageTrees = firstSum;
                pro.TalliedTrees    = talliedSum;
                pro.SumKPI          = totalKPI;
                pro.SumMeasuredKPI  = totalMeasuredKPI;
            }   //  end foreach loop

            //  Save list before continuing
            bslyr.SavePRO(proList);

            return;
        }   //  end SumTreeCountsPRO