コード例 #1
0
        }   //  end MakePopulationIDs

        // NOTE: Converted files - sum of KPI for 3P and S3P is the total of the SumKPI from the Count table
        //  plus the sum of measured KPI from the tree table.  No longer need to sum KPI from Count Tree and Tree
        //  April 2013
        //  methods to sum trees and KPI for individual methods
        public void SumTreeCountsLCD(string currST, List <CountTreeDO> ctList, List <PlotDO> justPlots,
                                     List <LCDDO> justCurrentLCD, string currMethod, List <LCDDO> lcdList)
        {
            CPbusinessLayer bslyr = new CPbusinessLayer();

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

            string currSG = "*";
            string prevSP = "*";

            //  Sums trees and counts from either the CountTree table or tree count records
            foreach (LCDDO lcd in justCurrentLCD)
            {
                firstSum         = 0.0;
                talliedSum       = 0.0;
                totalMeasuredKPI = 0.0;
                totalKPI         = 0.0;
                //  find measured trees for current LCD group
                List <TreeDO> lcdTrees = bslyr.getLCDtrees(lcd, "M");
                //  measured trees is just a count of the trees for current LCD group
                lcd.MeasuredTrees = lcdTrees.Count();

                //  now need count trees from tree count records
                List <TreeDO> lcdCntTrees = bslyr.getLCDtrees(lcd, "C");
                //  Sum all tree counts for first stage and total tallied
                //  see note in POP section on 100% method
                if (currMethod == "STR" || currMethod == "100")
                {
                    firstSum = lcdTrees.Count();
                }
                else if (currMethod != "3P")
                {
                    firstSum  = lcdTrees.Sum(tdo => tdo.TreeCount);
                    firstSum += lcdCntTrees.Sum(tdo => tdo.TreeCount);
                }
                if (lcd.STM == "Y")
                {
                    firstSum += lcd.MeasuredTrees;
                    //talliedSum += lcdTrees.Sum(tdo => tdo.TreeCount);
                    talliedSum += lcd.MeasuredTrees;
                }
                else
                {
                    //if (currMethod == "3P" || currMethod == "100")
                    if (currMethod == "100")
                    {
                        talliedSum += lcd.MeasuredTrees;
                    }
                    else
                    {
                        talliedSum  = lcdTrees.Sum(tdo => tdo.TreeCount);
                        talliedSum += lcdCntTrees.Sum(tdo => tdo.TreeCount);
                    } //  endif on current method
                }     //  endif
                //  insurance trees go into just the tallied tree count
                List <TreeDO> lcdInsurance = bslyr.getLCDtrees(lcd, "I");
                talliedSum += lcdInsurance.Sum(tdo => tdo.TreeCount);
                //  Complete totals based on method --  KPIs too
                List <CountTreeDO> lcdCountCounts = new List <CountTreeDO>();
                switch (currMethod)
                {
                case "STR":
                    currSG = "*";
                    prevSP = "*";
                    foreach (CountTreeDO ctd in ctList)
                    {
                        if (lcd.Stratum == ctd.SampleGroup.Stratum.Code &&
                            lcd.SampleGroup == ctd.SampleGroup.Code)
                        {
                            if (currSG != lcd.SampleGroup && prevSP != lcd.Species &&
                                (ctd.TreeDefaultValue_CN == 0 || ctd.TreeDefaultValue_CN == null))
                            {
                                //  multiple species for this sample group so avoid double counting
                                talliedSum += ctd.TreeCount;
                                currSG      = lcd.SampleGroup;
                                prevSP      = lcd.Species;
                            }
                            else if (currSG == lcd.SampleGroup && prevSP != lcd.Species &&
                                     (ctd.TreeDefaultValue_CN == 0 || ctd.TreeDefaultValue_CN == null))
                            {
                                //  do not add tree count
                                prevSP = lcd.Species;
                            }
                            else if (currSG != lcd.SampleGroup && prevSP != lcd.Species &&
                                     (ctd.TreeDefaultValue_CN > 0 || ctd.TreeDefaultValue_CN == null))
                            {
                                //  sample group probably doesn't have multiple species
                                talliedSum += ctd.TreeCount;
                            }
                            else if (currSG == lcd.SampleGroup && prevSP == lcd.Species &&
                                     (ctd.TreeDefaultValue_CN > 0 || ctd.TreeDefaultValue_CN == null))
                            {
                                talliedSum += ctd.TreeCount;
                            } //  endif
                        }     //  endif
                    }         //  end foreach count tree

                    break;

                case "3P":
                case "S3P":
                    lcdCountCounts = ctList.FindAll(
                        delegate(CountTreeDO ctd)
                    {
                        return(lcd.CutLeave == ctd.SampleGroup.CutLeave &&
                               lcd.Stratum == ctd.SampleGroup.Stratum.Code &&
                               lcd.SampleGroup == ctd.SampleGroup.Code &&
                               lcd.Species == ctd.TreeDefaultValue.Species &&
                               lcd.PrimaryProduct == ctd.SampleGroup.PrimaryProduct &&
                               lcd.SecondaryProduct == ctd.SampleGroup.SecondaryProduct &&
                               lcd.UOM == ctd.SampleGroup.UOM &&
                               lcd.LiveDead == ctd.TreeDefaultValue.LiveDead &&
                               lcd.Yield == ctd.SampleGroup.Stratum.YieldComponent &&
                               //  per K.Cormier, dropping contract species from LCD ID
                               //lcd.ContractSpecies == ctd.TreeDefaultValue.ContractSpecies &&
                               lcd.TreeGrade == ctd.TreeDefaultValue.TreeGrade);
                    });
                    if (lcd.STM == "N")
                    {
                        firstSum   += lcd.MeasuredTrees;
                        talliedSum += lcdCountCounts.Sum(ctd => ctd.TreeCount);
                        totalKPI   += lcdCountCounts.Sum(ctd => ctd.SumKPI);
                    }

                    //  Sum measured KPI from trees
                    totalMeasuredKPI = lcdTrees.Sum(tdo => tdo.KPI);
                    //  for S3P and 3P, sum of KPI is total of count and measured KPI from the trees == November 2013
                    //  even though KPI on an individual may be zero for one or the other
                    //  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 += lcdCntTrees.Sum(lc => lc.KPI);
                        totalKPI += lcdTrees.Sum(lt => lt.KPI);
                    }       //   endif on method
                    break;

                case "F3P":
                case "P3P":
                    //  Sum measured KPI from trees
                    totalMeasuredKPI = lcdTrees.Sum(tdo => tdo.KPI);
                    totalKPI         = lcdCntTrees.Sum(tdo => tdo.KPI);
                    totalKPI        += totalMeasuredKPI;
                    break;

                case "3PPNT":
                    //  this will probably no longer work on legacy data until
                    //  the conversion program handles this change
                    if (lcdTrees.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);
                    break;
                }   //  end switch on method

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

            //  Save list before continuing
            bslyr.SaveLCD(lcdList);
            return;
        }   //  end SumTreeCountsLCD