Пример #1
0
        private void cmbProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            string provinceName = (cmbProvince.SelectedItem as ComboBoxItem).Text;

            cmbCity.Items.Clear();
            string      name   = (cmbProvince.SelectedItem as ComboBoxItem).Text;
            List <City> cities = CityConfig.GetCitiesByProvinceName(name);

            foreach (City c in cities)
            {
                ComboBoxItem item1 = new ComboBoxItem();
                item1.Text = c.name;
                item1.Tag  = c.areacode;
                cmbCity.Items.Add(item1);
            }
            if (cmbCity.Items.Count > 0)
            {
                cmbCity.SelectedIndex = 0;
            }
        }
Пример #2
0
        private void cmbProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            string provinceName = cmbProvince.SelectedItem.ToString();

            if (provinceName == "全国")
            {
                cmbCity.Items.Clear();
                ComboBoxItem item = new ComboBoxItem();
                item.Text = "全部";
                item.Tag  = "";
                cmbCity.Items.Add(item);
            }
            else
            {
                cmbCity.Items.Clear();
                ComboBoxItem item = new ComboBoxItem();
                item.Text = "全部";
                item.Tag  = "";
                cmbCity.Items.Add(item);
                string      name   = cmbProvince.SelectedItem.ToString();
                List <City> cities = CityConfig.GetCitiesByProvinceName(name);
                foreach (City c in cities)
                {
                    ComboBoxItem item1 = new ComboBoxItem();
                    item1.Text = c.name;
                    item1.Tag  = c.areacode;
                    cmbCity.Items.Add(item1);
                }
                if (cmbCity.Items.Count == 2)//直辖市
                {
                    cmbCity.Items.Remove(cmbCity.Items[0]);
                }
            }
            if (cmbCity.Items.Count > 0)
            {
                cmbCity.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();
            }
        }