Пример #1
0
        public void ChangeSavedCityListByDrop(CityInfo sourceItem, CityInfo targetItem)
        {
            if (!InitComplete)
            {
                MessageBox.Show("天气信息正在排队初始化中,现在不能改变城市顺序,请稍后再试!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            InitComplete = false;

            try
            {
                SavedCityInfoList.Move(SavedCityInfoList.IndexOf(sourceItem), SavedCityInfoList.IndexOf(targetItem));

                Task.Factory.StartNew(() =>
                {
                    XmlHelper.WriteToXml(SavedCityInfoList.ToList());
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show("已保存城市顺序调整失败!\n" + ex.Message, "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            InitComplete = true;
        }
Пример #2
0
        public void DoubleClickItemGoToTop()
        {
            if (!InitComplete)
            {
                MessageBox.Show("天气信息正在排队初始化中,现在不能改变城市顺序,请稍后再试!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            InitComplete = false;

            try
            {
                if (DataGridSelectItemCityInfo != null)
                {
                    SavedCityInfoList.Move(SavedCityInfoList.IndexOf(DataGridSelectItemCityInfo), 0);

                    Task.Factory.StartNew(() =>
                    {
                        XmlHelper.WriteToXml(SavedCityInfoList.ToList());
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("已保存城市顺序调整失败!\n" + ex.Message, "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            InitComplete = true;
        }
Пример #3
0
        public void SearchCityAndSaveCityInfo()
        {
            if (!InitComplete)
            {
                MessageBox.Show("天气信息正在排队初始化中,现在不能新增城市,请稍后再试!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            try
            {
                if (string.IsNullOrEmpty(InputCityNameStr))
                {
                    MessageBox.Show("输入城市名为空!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                FindCityInfoList.Clear();

                foreach (var city in WeatherHelper.GetCityInfos(InputCityNameStr))
                {
                    FindCityInfoList.Add(city);
                }


                #region 加入保存列表、刷新显示

                if (FindCityInfoList.Count == 0)
                {
                    MessageBox.Show("未查询到该城市信息!\n\n仅能查询国内非港澳台地区!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                foreach (var savedCity in SavedCityInfoList)
                {
                    foreach (var findCity in FindCityInfoList)
                    {
                        if (savedCity.CityName == findCity.CityName && savedCity.CityCode == findCity.CityCode)
                        {
                            MessageBox.Show("保存失败!保存过程已被拦截。\n" + savedCity.CityName + "已经存在!", "系统提示", MessageBoxButton.OK,
                                MessageBoxImage.Warning);
                            return;
                        }
                    }
                }

                foreach (var city in FindCityInfoList)
                {
                    SavedCityInfoList.Add(city);
                }

                XmlHelper.WriteToXml(SavedCityInfoList.ToList());

                FindCityInfoList.Clear();

                //ShowErrorInfoStr("请添加完所有城市后手动刷新天气信息!");

                WriteLog("\t添加城市:" + InputCityNameStr);

                MessageBox.Show(InputCityNameStr + " 添加成功!它将排末尾。\n请添加完所有城市后手动刷新天气信息!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                InputCityNameStr = string.Empty;

                #endregion
            }
            catch (Exception ex)
            {
                ShowErrorInfoStr("添加城市过程中发生一个错误!\n" + ex.Message);
            }
        }