void getWeather(string city)
        {
            using (WebClient web = new WebClient())
            {
                string url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&units=metric&cnt=6,", city, APPID);

                var json = web.DownloadString(url);

                var result = JsonConvert.DeserializeObject <WeatherInfo.root>(json);

                WeatherInfo.root output = result;

                lbl_cityName.Text = string.Format("{0}", output.name);
                lbl_country.Text  = string.Format("{0}", output.sys.country);
                lbl_Temp.Text     = string.Format("{0}\u00B0", Convert.ToInt32(output.main.temp));
                lbl_feels.Text    = string.Format("Feels like {0}\u00B0C", Convert.ToInt32(output.main.feels_like));
                lbl_pressure.Text = string.Format("Barometer {0}mb", Convert.ToInt32(output.main.pressure));
                lbl_humid.Text    = string.Format("Humidity {0}%", Convert.ToInt32(output.main.humidity));
                lbl_wind.Text     = string.Format("Wind {0}km/h", (output.wind.speed) * 18 / 5);
                lbl_time.Text     = string.Format("Updated as of {0}", UnixTimeStampToDateTime(output.dt).TimeOfDay);
                lbl_date.Text     = string.Format("{0}", UnixTimeStampToDateTime(output.dt).ToShortDateString());
                lbl_day.Text      = string.Format("{0}", UnixTimeStampToDateTime(output.dt).DayOfWeek);
                lbl_direc.Text    = string.Format("{0}", DegreesToCardinalDetailed(output.wind.deg));
                lbl_cond.Text     = string.Format("{0}", output.weather[0].main);
                lbl_lon.Text      = string.Format("Longitude {0}", output.coord.lon);
                lbl_lat.Text      = string.Format("Latitude {0}", output.coord.lat);
            }
        }
Пример #2
0
        void getWeather(string city)

        {
            using (WebClient web = new WebClient())
            {
                string url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&units=metric&cnt=6", city, APPID);

                var json   = web.DownloadString(url);
                var result = JsonConvert.DeserializeObject <WeatherInfo.root>(json);
                WeatherInfo.root outPut = result;

                label1.Text          = string.Format("{0}", outPut.name);
                picturebox1.ImageUrl = string.Format("http://openweathermap.org/img/w/{0}.png", weatherInfo.list[0].weather[0].icon);
                label2.Text          = string.Format("{0}", outPut.sys.country);
                label3.Text          = string.Format("{0} \u00B0" + "C", outPut.main.temp);
            }
        }
Пример #3
0
        void getWeather(string city)
        {
            using (WebClient web = new WebClient())
            {
                string url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&units=metric&cnt=6", city, APPID); // you change parts of the url to equal objexts at the end

                var json = web.DownloadString(url);

                var result = JsonConvert.DeserializeObject <WeatherInfo.root>(json);

                WeatherInfo.root outPut = outPut = result;

                lbl_cityName.Text = string.Format("{0}", outPut.name);
                lbl_country.Text  = string.Format("{0}", outPut.sys.country);
                lbl_Temp.Text     = string.Format("{0} \u00B0" + "C", outPut.main.temp);

                picture_Main.Image = setIcon(outPut.weather[0].icon);
            }
        }
Пример #4
0
        void getWeather(string city)
        {
            using (WebClient web = new WebClient())
            {
                string url    = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&APPID={1}&units=metric&cnt=6", city, APPID);
                var    json   = web.DownloadString(url);
                var    result = JsonConvert.DeserializeObject <WeatherInfo.root>(json);

                WeatherInfo.root outPut = result;

                byte[] bytes = Encoding.Default.GetBytes(outPut.name);
                outPut.name = Encoding.UTF8.GetString(bytes);

                labelCityName.Text    = string.Format("{0}", outPut.name);
                labelCountryName.Text = string.Format("{0}", outPut.sys.country);
                labelScaleName.Text   = string.Format("{0} \u00B0" + "C", outPut.main.temp);

                pictureMain.Image = setIcon(outPut.weather[0].icon);
            }
        }
Пример #5
0
 void setLabels(WeatherInfo.root result)
 {
     WeatherInfo.root outPut = result;
     locLabel.Text       = string.Format("{0}, {1}", outPut.name, outPut.sys.country);
     cityTrendLabel.Text = locLabel.Text;
     if (unit)
     {
         tempLabel.Text = string.Format("{0} °C", Math.Round(outPut.main.temp, MidpointRounding.AwayFromZero));
     }
     else
     {
         tempLabel.Text = string.Format("{0} °F", Math.Round((outPut.main.temp * 5 / 9 + 32), MidpointRounding.AwayFromZero));
     }
     CurrentTemp.Text = locLabel.Text + " - " + tempLabel.Text;
     updateLabel.Text = "Updated: " + DateTime.Now.ToString();
     descLabel.Text   = string.Format("{0}", outPut.weatherList[0].main);
     humidLabel.Text  = string.Format("Humidity: {0}%", outPut.main.humidity);
     windLabel.Text   = string.Format("Wind speed: {0}m/s", outPut.wind.speed);
     addWeatherData(outPut.name, outPut.main.temp);
 }
Пример #6
0
        // For Today's Weather info
        void getWeather(string city)
        {
            using (WebClient web = new WebClient())
            {
                string url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&units=imperial", city, APPID);
                //** http://api.openweathermap.org/data/2.5/weather?q={0},us&appid={1}&units=imperial", city, APPID);

                try
                {
                    var json   = web.DownloadString(url);
                    var result = JsonConvert.DeserializeObject <WeatherInfo.root>(json);

                    WeatherInfo.root outPut = result;

                    lblCity.Text    = string.Format("{0}", outPut.name);
                    lblCountry.Text = string.Format("{0}", outPut.sys.country);
                    lblTemp.Text    = string.Format("{0:0}\u00B0 " + "F", outPut.main.temp);

                    lblCoord.Text   = string.Format("(Longitude: {0}  Latitude: {1})", outPut.coord.lon, outPut.coord.lat);
                    lblSunrise.Text = string.Format("Sunrise: {0}", getDate(outPut.sys.sunrise).TimeOfDay);
                    lblSunset.Text  = string.Format("Sunset: {0}", getDate(outPut.sys.sunset).TimeOfDay);
                    lblHigh.Text    = string.Format("{0:0}\u00B0 " + "F", outPut.main.temp_max);
                    lblLow.Text     = string.Format("{0:0}\u00B0 " + "F", outPut.main.temp_min);

                    //string URL = "https://mir-s3-cdn-cf.behance.net/project_modules/disp/8f342f30971807.563b2b138deaa.gif";
                    //picWeather1.Load(URL);

                    picSunrise.Load("http://openweathermap.org/img/w/01d.png");
                    picSunset.Load("http://openweathermap.org/img/w/01n.png");
                }
                catch (Exception)
                {
                    MessageBox.Show(txtSearchCity.Text + " not found.\r\nPlease enter correct city.");
                }
            }
        }
Пример #7
0
        // Refresh funtion
        // This function is triggered every time interval and by clicking refresh in context menu
        void refresh(string city)
        {
            try
            {
                // Get current weather
                string url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&units=metric", city, APPID);
                using (WebClient web = new WebClient())
                {
                    var json   = web.DownloadString(url);
                    var result = JsonConvert.DeserializeObject <WeatherInfo.root>(json);
                    WeatherInfo.root weatherInfo = result;

                    lbl_Location.Text = string.Format("{0},{1}", weatherInfo.name, weatherInfo.sys.country);
                    lbl_LastTime.Text = string.Format("{0:HH:mm:ss}", DateTime.Now);
                    //lbl_LastTime.Text = string.Format("{0:HH:mm:ss}", getDate(weatherInfo.dt));
                    if (this.tempUnit == 0)
                    {
                        lbl_Temp.Text = string.Format("{0:f} \u00B0" + "C", weatherInfo.main.temp);
                    }
                    else
                    {
                        lbl_Temp.Text = string.Format("{0:f} \u00B0" + "F", weatherInfo.main.temp * 1.8 + 32);
                    }
                    lbl_Humidity.Text         = string.Format("{0:f} %", weatherInfo.main.humidity);
                    lbl_WindSpeed.Text        = string.Format("{0:f} km/h", weatherInfo.wind.speed);
                    lbl_Condition.Text        = string.Format("{0}", weatherInfo.weather[0].description);
                    contextMenu.Items[0].Text = "Huidige temperatuur " + lbl_Temp.Text;
                    pictureBox1.ImageLocation = "http://openweathermap.org/img/w/" + weatherInfo.weather[0].icon + ".png";
                }
                // Forecast
                totalTemp = 0;
                url       = string.Format("http://api.openweathermap.org/data/2.5/forecast?q={0}&appid={1}&units=metric&cnt={2}", city, APPID, DAY_COUNT * 8);
                using (WebClient web = new WebClient())
                {
                    var json   = web.DownloadString(url);
                    var Object = JsonConvert.DeserializeObject <weatherForecast>(json);

                    weatherForecast forecast = Object;

                    // Show weather infos in dataGridView
                    dataGridView1.Rows.Clear();
                    dataGridView1.Refresh();
                    for (int i = 0; i < DAY_COUNT * 8; i++)
                    {
                        DataGridViewRow row = new DataGridViewRow();
                        row.CreateCells(dataGridView1);
                        if (this.tempUnit == 0)
                        {
                            row.Cells[0].Value = string.Format("{0:f} \u00B0" + "C", forecast.list[i].main.temp);
                        }
                        else
                        {
                            row.Cells[0].Value = string.Format("{0:f} \u00B0" + "F", forecast.list[i].main.temp * 1.8 + 32);
                        }
                        row.Cells[1].Value = this.location;
                        row.Cells[2].Value = string.Format("{0:MM/dd/yyyy HH:mm}", getDate(forecast.list[i].dt));
                        dataGridView1.Rows.Add(row);
                        totalTemp += forecast.list[i].main.temp;
                    }
                    if (this.tempUnit == 0)
                    {
                        lbl_AverTemp.Text = string.Format("{0:f} \u00B0" + "C", get_AverageTemp());
                    }
                    else
                    {
                        lbl_AverTemp.Text = string.Format("{0:f} \u00B0" + "F", get_AverageTemp() * 1.8 + 32);
                    }

                    foreach (var series in chart1.Series)
                    {
                        series.Points.Clear();
                    }
                    var chart = chart1.ChartAreas[0];
                    chart.AxisX.IntervalType = DateTimeIntervalType.Number;

                    chart.AxisX.LabelStyle.Format            = "";
                    chart.AxisY.LabelStyle.Format            = "";
                    chart.AxisY.LabelStyle.IsEndLabelVisible = true;

                    chart.AxisX.Minimum = 1;
                    chart.AxisX.Maximum = DAY_COUNT * 8;

                    chart.AxisX.Interval = 8;
                    if (this.tempUnit == 0)
                    {
                        chart.AxisY.LabelStyle.Format = "{0}\u00B0C";
                        chart.AxisY.Interval          = 5;
                    }
                    else
                    {
                        chart.AxisY.LabelStyle.Format = "{0}\u00B0F";
                        chart.AxisY.Interval          = 10;
                    }

                    chart.AxisX.Title          = "date";
                    chart.AxisX.TitleForeColor = Color.LightGreen;
                    chart.AxisX.TitleFont      = new Font("Arial", 12, FontStyle.Bold);

                    chart.AxisY.Title          = "Temp";
                    chart.AxisY.TitleForeColor = Color.Red;
                    chart.AxisY.TitleFont      = new Font("Arial", 12, FontStyle.Bold);

                    chart1.Series[0].IsVisibleInLegend = false;
                    //Here we'll draw the graph USING DATABASE
                    //we define table that gets data
                    DataTable dt = GetDataTable("select * from fivedaysinfo");
                    //this for loop will go throuh datatable
                    for (int i = 0; i < DAY_COUNT * 8; i++)
                    {     //this if is to check that datatable has data :)
                        if (i < dt.Rows.Count)
                        { //we plot graph as x value is date which is third column in datatable and y value is the degree which is first column
                            if (this.tempUnit == 0)
                            {
                                chart1.Series[0].Points.AddXY(dt.Rows[i][2].ToString().Remove(5), double.Parse(dt.Rows[i][0].ToString()));
                            }
                            //chart1.Series[0].Points.AddXY(string.Format("{0:MM/dd}", getDate(forecast.list[i].dt)), forecast.list[i].main.temp);
                            else
                            {
                                chart1.Series[0].Points.AddXY(dt.Rows[i][2].ToString().Remove(5), double.Parse(dt.Rows[i][0].ToString()) * 1.8 + 32);
                            }
                            //chart1.Series[0].Points.AddXY(string.Format("{0:MM/dd}", getDate(forecast.list[i].dt)), forecast.list[i].main.temp * 1.8 + 32);
                        }
                    }

                    saveData();
                }
            } catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }