예제 #1
0
        public static PopulationData Load(String fromFile)
        {
            StreamReader   reader = null;
            XmlDocument    xmlDoc = null;
            PopulationData result = null;

            try
            {
                if (!String.IsNullOrEmpty(fromFile) && File.Exists(fromFile))
                {
                    reader = new StreamReader(fromFile);
                    xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(reader.ReadToEnd());
                    result = PopulationData.Load(xmlDoc);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(result);
        }
예제 #2
0
        private void btnLoadConstituencyXml_Click(Object sender, EventArgs e)
        {
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Filter = "XML Files|*.xml|All files|*.*";
            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                PopulationData data   = null;
                StreamReader   reader = null;
                try
                {
                    reader = new StreamReader(openDialog.FileName);
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(reader.ReadToEnd());
                    foreach (XmlNode node in xmlDoc.ChildNodes)
                    {
                        if (node.Name == "electiondata")
                        {
                            data = PopulationData.Load(node);
                        }
                    }
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Dispose();
                    }
                }
                if ((data != null) && (data.Data != null))
                {
                    Int32 year = Convert.ToInt32(edtYear.Value);
                    PopulationDataEntry dataEntry = GetPopulationData(year);
                    if (rbxNational.Checked && chkBuengKan.Checked)
                    {
                        ModifyPopulationDataForBuengKan(dataEntry);
                    }
                    dataEntry.SortSubEntitiesByEnglishName();

                    var entitie = data.Data.FlatList(new List <EntityType>()
                    {
                        EntityType.Bangkok, EntityType.Changwat, EntityType.Amphoe, EntityType.KingAmphoe, EntityType.Khet
                    });
                    foreach (PopulationDataEntry entry in entitie)
                    {
                        entry.CopyPopulationToConstituencies(dataEntry);
                    }

                    ConstituencyStatisticsViewer dialog = new ConstituencyStatisticsViewer(data.Data);
                    dialog.Show();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Returns the tree of administrative subdivisions for a given province.
        /// </summary>
        /// <param name="provinceCode">TIS1099 code of the province.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <cref>provinceCode</cref> does not refer to a valid province.</exception>
        /// <returns>Tree of subdivisions.</returns>
        /// <remarks>Internally caches a clone of the returned value, to load the file from disc only once.</remarks>
        static public PopulationData GetGeocodeList(Int32 provinceCode)
        {
            PopulationData result = null;

            if (!ProvinceGeocodes.Any(entry => entry.Geocode == provinceCode))
            {
                throw new ArgumentOutOfRangeException("provinceCode");
            }
            if (_GeocodeCache.Keys.Contains(provinceCode))
            {
                result = new PopulationData((PopulationDataEntry)(_GeocodeCache[provinceCode].Clone()));
            }
            else
            {
                String fileName = TambonHelper.GeocodeSourceFile(provinceCode);
                if (File.Exists(fileName))
                {
                    result = PopulationData.Load(fileName);
                    _GeocodeCache.Add(provinceCode, (PopulationDataEntry)(result.Data.Clone()));
                }
            }
            return(result);
        }