Example #1
0
        private static void GetPopulationData(PopulationDataEntry iPopulation, List <PopulationDataEntry> iData)
        {
            if (iPopulation == null)
            {
                throw new ArgumentNullException("iPopulation", "No source for population data");
            }
            List <PopulationDataEntry> lNewEntityList = new List <PopulationDataEntry>();
            List <PopulationDataEntry> lThesabanList  = iPopulation.ThesabanList();

            foreach (PopulationDataEntry lConstituencyEntry in iData)
            {
                PopulationDataEntry lPopulationdataEntry = null;
                foreach (PopulationDataEntry lThesaban in lThesabanList)
                {
                    if (lThesaban.Geocode == lConstituencyEntry.Geocode)
                    {
                        lPopulationdataEntry = lThesaban;
                        break;
                    }
                }
                if (lPopulationdataEntry == null)
                {
                    lPopulationdataEntry = iPopulation.FindByCode(lConstituencyEntry.Geocode);
                }
                Debug.Assert(lPopulationdataEntry != null, "Entity with code " + lConstituencyEntry.Geocode.ToString() + " not found");
                if (lPopulationdataEntry != null)
                {
                    lNewEntityList.Add(lPopulationdataEntry);
                }
            }
            iData.Clear();
            iData.AddRange(lNewEntityList);
        }
        private IEnumerable <Tuple <Int32, Int32, Double> > CalcPopulationChanges(IEnumerable <PopulationDataEntry> entityList, PopulationDataEntry compare)
        {
            List <Tuple <Int32, Int32, Double> > result = new List <Tuple <Int32, Int32, Double> >();

            if (entityList.Any() && (compare != null))
            {
                IEnumerable <PopulationDataEntry> thesabanList = null;
                if ((EntityTypeHelper.IsCompatibleEntityType(EntityType.Thesaban, entityList.First().Type)))
                {
                    thesabanList = compare.ThesabanList();
                }
                foreach (PopulationDataEntry entity in entityList)
                {
                    if (entity.Geocode != 0)
                    {
                        PopulationDataEntry compareEntry;
                        if (EntityTypeHelper.IsCompatibleEntityType(EntityType.Thesaban, entity.Type))
                        {
                            compareEntry = thesabanList.FirstOrDefault(x => x.Geocode == entity.Geocode);
                        }
                        else
                        {
                            compareEntry = compare.FindByCode(entity.Geocode);
                        }
                        if ((compareEntry != null) && (compareEntry.Total > 0))
                        {
                            Int32  populationChange = entity.Total - compareEntry.Total;
                            Double changePercent    = 100.0 * populationChange / compareEntry.Total;
                            result.Add(Tuple.Create(entity.Geocode, populationChange, changePercent));
                        }
                    }
                }
            }
            return(result);
        }
 private IEnumerable<Tuple<Int32, Int32, Double>> CalcPopulationChanges(IEnumerable<PopulationDataEntry> entityList, PopulationDataEntry compare)
 {
     List<Tuple<Int32, Int32, Double>> result = new List<Tuple<Int32, Int32, Double>>();
     if ( entityList.Any() && (compare != null) )
     {
         IEnumerable<PopulationDataEntry> thesabanList = null;
         if ( (EntityTypeHelper.IsCompatibleEntityType(EntityType.Thesaban, entityList.First().Type)) )
         {
             thesabanList = compare.ThesabanList();
         }
         foreach ( PopulationDataEntry entity in entityList )
         {
             if ( entity.Geocode != 0 )
             {
                 PopulationDataEntry compareEntry;
                 if ( EntityTypeHelper.IsCompatibleEntityType(EntityType.Thesaban, entity.Type) )
                 {
                     compareEntry = thesabanList.FirstOrDefault(x => x.Geocode == entity.Geocode);
                 }
                 else
                 {
                     compareEntry = compare.FindByCode(entity.Geocode);
                 }
                 if ( (compareEntry != null) && (compareEntry.Total > 0) )
                 {
                     Int32 populationChange = entity.Total - compareEntry.Total;
                     Double changePercent = 100.0 * populationChange / compareEntry.Total;
                     result.Add(Tuple.Create(entity.Geocode, populationChange, changePercent));
                 }
             }
         }
     }
     return result;
 }
 private static void GetPopulationData(PopulationDataEntry iPopulation, List<PopulationDataEntry> iData)
 {
     if ( iPopulation == null )
     {
         throw new ArgumentNullException("iPopulation", "No source for population data");
     }
     List<PopulationDataEntry> lNewEntityList = new List<PopulationDataEntry>();
     List<PopulationDataEntry> lThesabanList = iPopulation.ThesabanList();
     foreach ( PopulationDataEntry lConstituencyEntry in iData )
     {
         PopulationDataEntry lPopulationdataEntry = null;
         foreach ( PopulationDataEntry lThesaban in lThesabanList )
         {
             if ( lThesaban.Geocode == lConstituencyEntry.Geocode )
             {
                 lPopulationdataEntry = lThesaban;
                 break;
             }
         }
         if ( lPopulationdataEntry == null )
         {
             lPopulationdataEntry = iPopulation.FindByCode(lConstituencyEntry.Geocode);
         }
         Debug.Assert(lPopulationdataEntry != null, "Entity with code " + lConstituencyEntry.Geocode.ToString() + " not found");
         if ( lPopulationdataEntry != null )
         {
             lNewEntityList.Add(lPopulationdataEntry);
         }
     }
     iData.Clear();
     iData.AddRange(lNewEntityList);
 }
        private IEnumerable <PopulationDataEntry> CalculateList()
        {
            List <PopulationDataEntry> list     = new List <PopulationDataEntry>();
            List <EntityType>          entities = new List <EntityType>();

            if (rbx_Changwat.Checked)
            {
                entities.Add(EntityType.Changwat);
                entities.Add(EntityType.Bangkok);
                list.AddRange(BaseEntry.FlatList(entities));
                if (entities.Contains(BaseEntry.Type))
                {
                    list.Add(BaseEntry);
                }
            }
            else if (rbxAmphoeKhet.Checked)
            {
                if (chkAmphoe.Checked)
                {
                    entities.Add(EntityType.Amphoe);
                }
                if (chkKhet.Checked)
                {
                    entities.Add(EntityType.Khet);
                }
                list.AddRange(_baseEntry.FlatList(entities));
            }
            else if (rbxTambonKhwaeng.Checked)
            {
                if (chkTambon.Checked)
                {
                    entities.Add(EntityType.Tambon);
                }
                if (chkKhwaeng.Checked)
                {
                    entities.Add(EntityType.Khwaeng);
                }
                list.AddRange(_baseEntry.FlatList(entities));
            }
            else if (rbxThesaban.Checked)
            {
                if (chkThesabanTambon.Checked)
                {
                    entities.Add(EntityType.ThesabanTambon);
                }
                if (chkThesabanMueang.Checked)
                {
                    entities.Add(EntityType.ThesabanMueang);
                }
                if (chkThesabanNakhon.Checked)
                {
                    entities.Add(EntityType.ThesabanNakhon);
                }

                foreach (PopulationDataEntry entity in _baseEntry.ThesabanList())
                {
                    if (entities.Contains(entity.Type))
                    {
                        list.Add(entity);
                    }
                }
            }

            list.Sort(delegate(PopulationDataEntry p1, PopulationDataEntry p2)
            {
                return(p2.Total.CompareTo(p1.Total));
            });
            return(list);
        }