예제 #1
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;
        }
예제 #2
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;
        }
예제 #3
0
        public void GetSavedCityFromXml()
        {
            try
            {
                if (SavedCityInfoList.Count != 0)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        SavedCityInfoList.Clear();
                    });
                }

                foreach (var city in XmlHelper.ReadFromXml())
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        SavedCityInfoList.Add(city);
                    });
                }

                if (SavedCityInfoList.Count > 0)
                {
                    ListSelectItemCityInfo = SavedCityInfoList[0];
                }
            }
            catch (Exception ex)
            {
                ShowErrorInfoStr("从XML中取出已保存城市过程中发生错误!\n" + ex.Message);
            }
        }
예제 #4
0
        private void DeleteSavedCity()
        {
            if (!InitComplete)
            {
                MessageBox.Show("天气信息正在排队初始化中,现在不能删除城市,请稍后再试!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            MessageBoxResult mbr = MessageBox.Show("确定删除所有勾选项吗?", "系统提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
            if (mbr != MessageBoxResult.Yes)
            {
                return;
            }

            try
            {
                List<CityInfo> waitDeleteCityInfoList = (from cityInfo in SavedCityInfoList
                                                         where cityInfo.SelectStatus
                                                         select cityInfo).ToList();

                if (waitDeleteCityInfoList.Count == 0)
                {
                    WriteLog("\t删除城市:" + DataGridSelectItemCityInfo.CityName);

                    XmlHelper.DeleteFromXml(DataGridSelectItemCityInfo);
                    SavedCityInfoList.Remove(DataGridSelectItemCityInfo);
                }
                else
                {
                    foreach (var delectCity in waitDeleteCityInfoList)
                    {
                        XmlHelper.DeleteFromXml(delectCity);
                        SavedCityInfoList.Remove(delectCity);
                    }

                    string deleteCity = string.Empty;
                    foreach (var cityInfo in waitDeleteCityInfoList)
                    {
                        deleteCity += cityInfo.CityName + " ";
                    }
                    WriteLog("\t删除城市:" + deleteCity);
                }
            }
            catch (Exception ex)
            {
                ShowErrorInfoStr("城市删除时发生错误!\n" + ex.Message);
            }
        }
예제 #5
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);
            }
        }