Exemple #1
0
        private WeatherDetail Search(PlaceModel province, PlaceModel city, PlaceModel district)
        {
            WeatherDetail detail = new WeatherDetail(province, city, district);

            detail.HandleWeather();
            return(detail);
        }
Exemple #2
0
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            PlaceModel province = null, city = null, district = null;

            this.InvokeToForm(() =>
            {
                province = this.comboBoxProvince.ComboBox.SelectedItem as PlaceModel;
                city     = this.comboBoxCity.ComboBox.SelectedItem as PlaceModel;
                district = this.comboBoxDistrict.ComboBox.SelectedItem as PlaceModel;
            });
            if (province != null && city != null && district != null)
            {
                this.InvokeToForm(() => lblStatus.Text = "查询中");
                Task.Factory.StartNew(() =>
                {
                    WeatherDetail detail = this.Search(province, city, district);
                    this.Invoke(new Action(() =>
                    {
                        this.SetWeather(detail);
                        lblStatus.Text = "已完成";
                    }));
                }).ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        this.InvokeToForm(() => lblStatus.Text = "查询错误,请确保联网正确");
                    }
                });
            }
        }
Exemple #3
0
        public override bool Equals(object obj)
        {
            PlaceModel pm = (PlaceModel)obj;

            if (this.ID == pm.ID && this.Name == pm.Name)
            {
                return(true);
            }
            return(false);
        }
Exemple #4
0
        private void BindCity()
        {
            PlaceModel city = null;

            this.InvokeToForm(() =>
            {
                comboBoxCity.ComboBox.ValueMember   = "ID";
                comboBoxCity.ComboBox.DisplayMember = "Name";
                city = comboBoxProvince.ComboBox.SelectedItem as PlaceModel;
            });
            if (city != null)
            {
                PlaceModel[] citys = Place.GetCitys(city);
                this.InvokeToForm(() => comboBoxCity.ComboBox.DataSource = citys);
            }
        }
Exemple #5
0
        private void BindDistrict()
        {
            PlaceModel province = null;
            PlaceModel city     = null;

            this.InvokeToForm(() =>
            {
                comboBoxDistrict.ComboBox.ValueMember   = "ID";
                comboBoxDistrict.ComboBox.DisplayMember = "Name";
                province = comboBoxProvince.ComboBox.SelectedItem as PlaceModel;
                city     = comboBoxCity.ComboBox.SelectedItem as PlaceModel;
            });
            if (province != null && city != null)
            {
                PlaceModel[] districts = Place.GetDistricts(province, city);
                this.InvokeToForm(() => comboBoxDistrict.ComboBox.DataSource = districts);
            }
            else
            {
                this.InvokeToForm(() => lblStatus.Text = "地区加载错误,请确保联网正确");
            }
        }
Exemple #6
0
        private void BindMenu()
        {
            buttonCustom.DropDownItems.Clear();
            //ToolStripMenuItem
            areas = XmlOperator.Deserialize <AreaCollection>(path);
            if (areas != null)
            {
                for (int i = 0; i < areas.Areas.Length; i++)
                {
                    ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem
                    {
                        Name = $"toolStripMenuItem_{areas.Areas[i].Province.Name}_{areas.Areas[i].City.Name}_{areas.Areas[i].District.Name}",
                        Text = areas.Areas[i].Name,
                        Tag  = areas.Areas[i]
                    };
                    toolStripMenuItem.Click += (s, o) =>
                    {
                        ToolStripMenuItem _toolStripMenuItem = (ToolStripMenuItem)s;
                        Area area = (Area)_toolStripMenuItem.Tag;
                        comboBoxProvince.SelectedItem = area.Province;
                        comboBoxCity.SelectedItem     = area.City;
                        comboBoxDistrict.SelectedItem = area.District;
                        buttonSearch.PerformClick();
                    };
                    buttonCustom.DropDownItems.Add(toolStripMenuItem);
                }
            }
            else
            {
                areas = new AreaCollection();
            }
            buttonCustom.DropDownItems.Add(new ToolStripSeparator());
            ToolStripMenuItem toolStripMenuItem1 = new ToolStripMenuItem()
            {
                Name = "toolStripMenuItem_AddCity",
                Text = "添加城市",
            };

            toolStripMenuItem1.Click += (s, o) =>
            {
                PlaceModel province = comboBoxProvince.ComboBox.SelectedItem as PlaceModel;
                PlaceModel city     = comboBoxCity.ComboBox.SelectedItem as PlaceModel;
                PlaceModel district = comboBoxDistrict.ComboBox.SelectedItem as PlaceModel;
                if (province != null && city != null && district != null)
                {
                    areas.Add(new Area()
                    {
                        Name = district.Name, Province = province, City = city, District = district
                    });
                    XmlOperator.Serialize(path, areas);
                    BindMenu();
                }
            };
            buttonCustom.DropDownItems.Add(toolStripMenuItem1);


            ToolStripMenuItem toolStripMenuItem2 = new ToolStripMenuItem()
            {
                Name = "toolStripMenuItem_DeleteCity",
                Text = "删除城市",
            };

            toolStripMenuItem2.Click += (s, o) =>
            {
                PlaceModel province = comboBoxProvince.ComboBox.SelectedItem as PlaceModel;
                PlaceModel city     = comboBoxCity.ComboBox.SelectedItem as PlaceModel;
                PlaceModel district = comboBoxDistrict.ComboBox.SelectedItem as PlaceModel;
                if (province != null && city != null && district != null)
                {
                    areas.Remove(new Area()
                    {
                        Name = district.Name, Province = province, City = city, District = district
                    });
                    XmlOperator.Serialize(path, areas);
                    BindMenu();
                }
            };
            buttonCustom.DropDownItems.Add(toolStripMenuItem2);
        }
Exemple #7
0
 public static PlaceModel[] GetDistricts(PlaceModel province, PlaceModel city)
 {
     return(GetPlaceList($"http://www.weather.com.cn/data/city3jdata/station/{province.ID}{city.ID}.html"));
 }
Exemple #8
0
 public static PlaceModel[] GetCitys(PlaceModel province)
 {
     return(GetPlaceList($"http://www.weather.com.cn/data/city3jdata/provshi/{province.ID}.html"));
 }
Exemple #9
0
 public WeatherDetail(PlaceModel province, PlaceModel city, PlaceModel district)
 {
     this.province = province;
     this.city     = city;
     this.district = district;
 }