Esempio n. 1
0
        private void cmbCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbDistrict.Items.Clear();
            ComboBoxItem item = new ComboBoxItem();

            item.Text = "全部";
            item.Tag  = "";
            cmbDistrict.Items.Add(item);
            string          name      = cmbCity.SelectedItem.ToString();
            List <District> districts = CityConfig.GetDistrictsByCityName(name);

            foreach (District d in districts)
            {
                ComboBoxItem item1 = new ComboBoxItem();
                item1.Text = d.name;
                item1.Tag  = d.areacode;
                cmbDistrict.Items.Add(item1);
            }
            if (cmbDistrict.Items.Count > 0)
            {
                cmbDistrict.SelectedIndex = 0;
            }
        }
        //private int timeOut = 2000;
        /// <summary>
        /// 下载百度行政区划图
        /// </summary>
        /// <param name="name">下载城市名称,可以是全国,省,市,县</param>
        /// <param name="areaCode"></param>
        /// <param name="type">名称所属类型,属于国家,还是省,市,区 ,县</param>
        public void DownAdminDivision(string name, string areaCode, CityType type)
        {
            switch (type)
            {
            case CityType.Country:
                List <Province> provinces = CityConfig.GetInstance().Countryconfig.countries;
                int             index     = 1;
                int             count     = 1;
                foreach (Province p in provinces)
                {
                    count++;
                    foreach (City c in p.cities)
                    {
                        count++;
                        count += c.districts.Count;
                    }
                }
                this.DownPositions(name, "", type, index, count, "");
                foreach (Province p in provinces)
                {
                    index++;
                    this.DownPositions(p.name, p.areacode, CityType.Province, index, count, p.baiduCode);
                    foreach (City c in p.cities)
                    {
                        index++;
                        this.DownPositions(c.name, c.areacode, CityType.City, index, count, c.baiduCode);
                    }
                }
                break;

            case CityType.Province:
                int pindex = 1;
                int pcount = 1;
                this.DownPositions(name, areaCode, CityType.Province, pindex, pcount, "");
                List <City> cities = CityConfig.GetCitiesByProvinceName(name);
                foreach (City c in cities)
                {
                    pcount++;
                    pcount += c.districts.Count;
                }
                foreach (City c in cities)
                {
                    pindex++;
                    this.DownPositions(c.name, c.areacode, CityType.City, pindex, pcount, c.baiduCode);
                    foreach (District d in c.districts)
                    {
                        pindex++;
                        this.DownPositions(d.name, c.areacode, CityType.District, pindex, pcount, d.baiduCode);
                    }
                }
                break;

            case CityType.City:
                List <District> districts = CityConfig.GetDistrictsByCityName(name);
                int             cindex    = 1;
                int             ccount    = 1 + districts.Count;
                if (!name.Contains("市") && !name.Contains("自治"))
                {
                    name = name + "市";
                }
                this.DownPositions(name, "", type, cindex, ccount, "");
                foreach (District d in districts)
                {
                    cindex++;
                    this.DownPositions(d.name, d.areacode, CityType.District, cindex, ccount, d.baiduCode);
                }
                break;

            case CityType.District:
                this.DownPositions(name, areaCode, CityType.District, 1, 1, "");
                break;
            }
            if (this.AdminDivisionDownedEvent != null)
            {
                this.AdminDivisionDownedEvent();
            }
        }