예제 #1
0
        private void GetFavoritesInfo(string cityName)
        {
            var result = openWeatherMapApi.GetApiResult(cityName, _apiKey);

            lblCity.Text     = Properties.Settings.Default.CityNamePersion;
            lblCityMain.Text = Properties.Settings.Default.CityNamePersion;
            lblLat.Text      = result.coord.lat;
            lblLng.Text      = result.coord.lon;
            lblTemp.Text     = GetWeatherImage.ConvertKelvinToCantigerad(result.main.temp);
            lblSpeed.Text    = result.wind.speed.ToString();
            lblHumidity.Text = result.main.humidity.ToString();
            lblPressure.Text = result.main.pressure;

            lblSunrise.Text = GetWeatherImage.ConvertUnixToDateTime
                                  (double.Parse(result.sys.sunrise.ToString()));
            lblSunset.Text = GetWeatherImage.ConvertUnixToDateTime
                                 (double.Parse(result.sys.sunset.ToString()));

            picWeather.Image    = GetWeatherImage.GetImage(result.weather[0].id);
            lblDescription.Text = GetWeatherImage.GetDescription(result.weather[0].id);
        }
예제 #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            var json       = File.ReadAllText("CityList.json");
            var playerList = JsonConvert.DeserializeObject <List <CityModel> >(json);
            int row        = playerList.Count;

            foreach (var item in playerList)
            {
                var result = openWeatherMapApi.GetApiResult(item.Name, _apiKey);

                var userControl = new RowWeather
                {
                    Row            = row,
                    NamePersion    = item.Persion,
                    Degre          = " C° " + GetWeatherImage.ConvertKelvinToCantigerad(result.main.temp),
                    PictureWeather = result.weather[0].id,
                    Odd            = (row % 2) != 0,
                    Dock           = DockStyle.Top,
                    Name           = "UserControlWeather" + row
                };
                userControl.btnFavorites.Click += (s, args) =>
                {
                    AddFavorites(item.Name, item.Persion);
                };

                scrollBar.Controls.Add(userControl);
                row--;
            }

            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.CityName))
            {
                GetFavoritesInfo(Properties.Settings.Default.CityName);
            }
            GetUserInformation();
            lblDayName.Text = GetDayName();
        }