コード例 #1
0
        private void Searchbox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            if (Searchbox.Text.Contains(","))
            {
                location = Searchbox.Text.Split(',')[0];
            }
            else
            {
                location = Searchbox.Text;
            }
            string Now_URL = "https://free-api.heweather.net/s6/weather/now";
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("location", location);
            dic.Add("key", key);
            Function.Weather nowWeather = null;
            try
            {
                nowWeather = JsonConvert.DeserializeObject <Function.Weather>(Function.HTTP.Get(Now_URL, dic));
            }
            catch (Exception e)
            {
                nowWeather = JsonConvert.DeserializeObject <Function.Weather>(Function.HTTP.Get(Now_URL, dic));
            }
            if (nowWeather.HeWeather6[0].status == "ok")
            {
                Update_NowWeather(nowWeather);
            }
            ShowChart(location);
            load_Dalily(location);
            load_des(location);
        }
コード例 #2
0
        private void load_Dalily(string location = "auto_ip")
        {
            this.Invoke(() =>
            {
                string Dalily_URL = "https://free-api.heweather.net/s6/weather/forecast";
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("location", location);
                dic.Add("key", key);
                ListViewRiver.Items.Clear();
                ObservableCollection <model.WeatherCard> Dalily = new ObservableCollection <model.WeatherCard>();
                Function.Weather daylilyWeather = null;
                try
                {
                    daylilyWeather = JsonConvert.DeserializeObject <Function.Weather>(Function.HTTP.Get(Dalily_URL, dic));
                }catch (Exception e)
                {
                    daylilyWeather = JsonConvert.DeserializeObject <Function.Weather>(Function.HTTP.Get(Dalily_URL, dic));
                }

                foreach (Function.Daily_forecast day in daylilyWeather.HeWeather6[0].daily_forecast)
                {
                    ListViewRiver.Items.Add(new Weather.model.WeatherCard(day));
                }
                sunup.Text    = daylilyWeather.HeWeather6[0].daily_forecast[0].sr;
                sundown.Text  = daylilyWeather.HeWeather6[0].daily_forecast[0].ss;
                moonup.Text   = daylilyWeather.HeWeather6[0].daily_forecast[0].mr;
                moondown.Text = daylilyWeather.HeWeather6[0].daily_forecast[0].ms;
            });
        }
コード例 #3
0
 public FavCard(Function.Weather weather)
 {
     this.InitializeComponent();
     Loadbackground(weather);
     location.Text = weather.HeWeather6[0].basic.cnty.Replace("中国", "中华人民共和国") + weather.HeWeather6[0].basic.location;
     tmp.Text      = weather.HeWeather6[0].now.tmp + "℃";
     des.Text      = weather.HeWeather6[0].now.cond_txt;
     fs.Text       = weather.HeWeather6[0].now.wind_spd + "公里/小时";
     fx.Rotation   = Convert.ToDouble(weather.HeWeather6[0].now.wind_deg) + 90;
     sd.Text       = weather.HeWeather6[0].now.hum + "%";
     loca          = weather.HeWeather6[0].basic.location;
 }
コード例 #4
0
        private void Update_NowWeather(Function.Weather nowWeather)
        {
            Loadbackground(nowWeather);
            City.Text = nowWeather.HeWeather6[0].basic.cnty.Replace("中国", "中华人民共和国") + nowWeather.HeWeather6[0].basic.location;
            BitmapImage i = new BitmapImage(new Uri(new StringBuilder("ms-appx:///Resource/WeatherIcon/128/").Append(ChangeNightIcon(nowWeather.HeWeather6[0].now.cond_code)).Append(".png").ToString()));

            Icon.Source    = i;
            Temp.Text      = nowWeather.HeWeather6[0].now.tmp + "℃";
            des.Text       = nowWeather.HeWeather6[0].now.cond_txt;
            tiganTemp.Text = "体感温度  " + nowWeather.HeWeather6[0].now.fl + "℃";
            fx.Rotation    = Convert.ToDouble(nowWeather.HeWeather6[0].now.wind_deg) + 90;
            fs.Text        = nowWeather.HeWeather6[0].now.wind_spd + "公里/小时";
            njd.Text       = nowWeather.HeWeather6[0].now.vis + "公里";
            qyj.Text       = nowWeather.HeWeather6[0].now.pres + "百帕";
            sd.Text        = nowWeather.HeWeather6[0].now.hum + "%";
            yl.Text        = nowWeather.HeWeather6[0].now.cloud;
            time.Text      = "最后更新时间: " + nowWeather.HeWeather6[0].update.loc.ToString("HH:mm");
        }
コード例 #5
0
 private void load_des(string location = "auto_ip")
 {
     this.Invoke(() =>
     {
         string life_URL = "https://free-api.heweather.net/s6/weather/lifestyle";
         Dictionary <string, string> dic = new Dictionary <string, string>();
         dic.Add("location", location);
         dic.Add("key", key);
         Function.Weather lifeWeather = null;
         try
         {
             lifeWeather = JsonConvert.DeserializeObject <Function.Weather>(Function.HTTP.Get(life_URL, dic));
         }
         catch (Exception e)
         {
             lifeWeather = JsonConvert.DeserializeObject <Function.Weather>(Function.HTTP.Get(life_URL, dic));
         }
         comfortable.Text = lifeWeather.HeWeather6[0].lifestyle[0].brf + "," + lifeWeather.HeWeather6[0].lifestyle[0].txt;
         cloth.Text       = lifeWeather.HeWeather6[0].lifestyle[1].txt;
     });
 }
コード例 #6
0
        private void loadWeather(string location)
        {
            string Now_URL = "https://free-api.heweather.net/s6/weather/now";
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("location", location);
            dic.Add("key", key);
            Function.Weather nowWeather = null;
            try
            {
                nowWeather = JsonConvert.DeserializeObject <Function.Weather>(Function.HTTP.Get(Now_URL, dic));
            }
            catch (Exception e)
            {
                nowWeather = JsonConvert.DeserializeObject <Function.Weather>(Function.HTTP.Get(Now_URL, dic));
            }

            if (nowWeather.HeWeather6[0].status == "ok")
            {
                Update_NowWeather(nowWeather);
            }
        }
コード例 #7
0
        private void Loadbackground(Function.Weather weather)
        {
            TimeSpan span3 = DateTime.Parse("19:30").TimeOfDay;
            TimeSpan span2 = DateTime.Parse("14:30").TimeOfDay;
            TimeSpan span1 = DateTime.Parse("06:00").TimeOfDay;

            if (DateTime.Now.TimeOfDay >= span1 && DateTime.Now.TimeOfDay <= span2)
            {
                if (weather.HeWeather6[0].now.cond_txt.Contains("雨"))
                {
                    BitmapImage i = new BitmapImage(new Uri("ms-appx:///Resource/background/201.jpg"));
                    background.Source = i;
                }
                else if (weather.HeWeather6[0].now.cond_txt.Contains("雪"))
                {
                    BitmapImage i = new BitmapImage(new Uri("ms-appx:///Resource/background/301.jpg"));
                    background.Source = i;
                }
                else
                {
                    BitmapImage i = new BitmapImage(new Uri("ms-appx:///Resource/background/101.jpg"));
                    background.Source = i;
                }
            }
            else if (DateTime.Now.TimeOfDay >= span2 && DateTime.Now.TimeOfDay <= span3)
            {
                if (weather.HeWeather6[0].now.cond_txt.Contains("雨"))
                {
                    BitmapImage i = new BitmapImage(new Uri("ms-appx:///Resource/background/202.jpg"));
                    background.Source = i;
                }
                else if (weather.HeWeather6[0].now.cond_txt.Contains("雪"))
                {
                    BitmapImage i = new BitmapImage(new Uri("ms-appx:///Resource/background/302.jpg"));
                    background.Source = i;
                }
                else
                {
                    BitmapImage i = new BitmapImage(new Uri("ms-appx:///Resource/background/102.jpg"));
                    background.Source = i;
                }
            }
            else if (DateTime.Now.TimeOfDay >= span3 || DateTime.Now.TimeOfDay <= span1)
            {
                if (weather.HeWeather6[0].now.cond_txt.Contains("雨"))
                {
                    BitmapImage i = new BitmapImage(new Uri("ms-appx:///Resource/background/203.jpg"));
                    background.Source = i;
                }
                else if (weather.HeWeather6[0].now.cond_txt.Contains("雪"))
                {
                    BitmapImage i = new BitmapImage(new Uri("ms-appx:///Resource/background/303.jpg"));
                    background.Source = i;
                }
                else
                {
                    BitmapImage i = new BitmapImage(new Uri("ms-appx:///Resource/background/103.jpg"));
                    background.Source = i;
                }
            }
        }
コード例 #8
0
        private void ShowChart(string location = "auto_ip")
        {
            this.Invoke(async() =>
            {
                string Dalily_URL = "https://free-api.heweather.net/s6/weather/hourly";
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("location", location);
                dic.Add("key", key);
                if (tmpchart.Series != null)
                {
                    tmpchart.Series.Clear();
                }
                Function.Weather hourlyWeather = null;
                try
                {
                    hourlyWeather = JsonConvert.DeserializeObject <Function.Weather>(Function.HTTP.Get(Dalily_URL, dic));
                }catch (Exception e)
                {
                    hourlyWeather = JsonConvert.DeserializeObject <Function.Weather>(Function.HTTP.Get(Dalily_URL, dic));
                }

                LineSeries mylineseries = new LineSeries();
                LineSeries weatherlines = new LineSeries();
                sec                          = new SeriesCollection {
                };
                tmpchart.Series              = sec;
                weatherlines.Values          = new ChartValues <double>();
                mylineseries.LineSmoothness  = 2;
                mylineseries.PointGeometry   = DefaultGeometries.None;
                mylineseries.Values          = new ChartValues <double>();
                mylineseries.Foreground      = new SolidColorBrush(Windows.UI.Colors.White);
                mylineseries.FontSize        = 14;
                weatherlines.LineSmoothness  = 2;
                weatherlines.Foreground      = new SolidColorBrush(Windows.UI.Colors.White);
                weatherlines.PointGeometry   = DefaultGeometries.None;
                weatherlines.Values          = new ChartValues <double>();
                weatherlines.FontSize        = 14;
                weatherlines.StrokeThickness = 0.5;
                weatherlines.Opacity         = 0.2;
                sec.Add(mylineseries);
                sec.Add(weatherlines);
                tmpchart.AxisX[0].Separator = new Separator
                {
                    Step            = 1,
                    StrokeThickness = 0,
                };
                tmpchart.AxisY[0].Separator = new Separator
                {
                    Step            = 5,
                    StrokeThickness = 0,
                };
                var temlist              = new List <double>();
                Labels                   = new List <string>();
                DataContext              = this;
                mylineseries.DataLabels  = true;
                List <string> lablepoint = new List <string>();
                foreach (Function.Hourly h in hourlyWeather.HeWeather6[0].hourly)
                {
                    mylineseries.Values.Add(Convert.ToDouble(h.tmp));
                    temlist.Add(Convert.ToDouble(h.tmp));

                    mylineseries.LabelPoint = point => point.Y + "℃";
                    Labels.Add(h.time.ToString("HH:mm") + "\n " + h.pop + "%");
                    lablepoint.Add(h.cond_txt);
                }
                var v = (temlist.Max() + temlist.Min()) / 8;
                weatherlines.DataLabels = true;
                foreach (Function.Hourly h in hourlyWeather.HeWeather6[0].hourly)
                {
                    weatherlines.Values.Add(v);
                    weatherlines.LabelPoint = p =>
                    {
                        return(lablepoint[p.Key]);
                    };
                    await Task.Delay(180);
                }
            });
        }