partial void DeleteIconsTable(IconsTable instance);
 partial void UpdateIconsTable(IconsTable instance);
Пример #3
0
        void getWeather()
        {
            using (WebClient web = new WebClient())
            {
                string url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&units=metric&cnt=3", cityName, 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" + "C", outPut.main.temp);
                lbl_Conditions1.Text  = string.Format("{0}", outPut.weather[0].main);
                lbl_Description1.Text = string.Format("{0}", outPut.weather[0].description);
                lbl_WindSpeed1.Text   = string.Format("{0} km/h", outPut.wind.speed);

                string        connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\serge\source\repos\BaigiamasisDarbas_Orai_Sergej\BaigiamasisDarbas_Orai_Sergej\City.mdf;Integrated Security=True";
                SqlConnection sql     = new SqlConnection(connectionString);
                string        querry  = "SELECT TOP 1 * FROM IconsTable";
                SqlCommand    command = new SqlCommand(querry, sql);
                sql.Open();
                SqlDataReader takeIcon = command.ExecuteReader();
                while (takeIcon.Read())
                {
                    IconsTable iconsTable = new IconsTable();
                    iconsTable.Icons = takeIcon["Icons"].ToString();
                    IconChangeVar    = iconsTable.Icons;
                }
                sql.Close();

                SunriseNow = outPut.sys.sunrise;
                SunsetNow  = outPut.sys.sunset;
                TimeNow    = outPut.dt;


                if (IconChangeVar == null)
                {
                    string iconNr1 = outPut.weather[0].icon;

                    string url1 = string.Format("http://openweathermap.org/img/wn/{0}@2x.png", iconNr1);

                    WebRequest request1 = WebRequest.Create(url1);
                    using (var response1 = request1.GetResponse())
                    {
                        using (var str1 = response1.GetResponseStream())
                        {
                            pictureBox1.Image = Bitmap.FromStream(str1);
                        }
                    }
                }
                else
                {
                    ChangeIcon1();
                }

                if (outPut.dt >= outPut.sys.sunrise && outPut.dt <= outPut.sys.sunset)
                {
                    BackgroundImage = Properties.Resources.day;
                }
                else
                {
                    BackgroundImage = Properties.Resources.night;
                }
            }
        }
 partial void InsertIconsTable(IconsTable instance);
Пример #5
0
        void getForcast()
        {
            int    day = 10;
            string url = string.Format("http://api.openweathermap.org/data/2.5/forecast?q={0}&units=metric&cnt={1}&APPID={2}", cityName, day, APPID);

            using (WebClient web = new WebClient())
            {
                var json   = web.DownloadString(url);
                var Object = JsonConvert.DeserializeObject <WeatherForcast>(json);

                WeatherForcast forcast = Object;

                DayNight2 = forcast.list[0].sys.pod;
                DayNight3 = forcast.list[3].sys.pod;
                DayNight4 = forcast.list[6].sys.pod;
                DayNight5 = forcast.list[9].sys.pod;



                lbl_Days2.Text        = string.Format("{0}", forcast.list[0].dt_txt);
                lbl_Conditions2.Text  = string.Format("{0}", forcast.list[0].weather[0].main);        //oro būsena
                lbl_Description2.Text = string.Format("{0}", forcast.list[0].weather[0].description); //oro aprašimas
                lbl_daysTemp2.Text    = string.Format("{0} \u00B0" + "C", forcast.list[0].main.temp); //oro temperatūra
                lbl_WindSpeed2.Text   = string.Format("{0} km/h", forcast.list[0].wind.speed);        //vėjo greitis



                lbl_Days3.Text        = string.Format("{0}", forcast.list[3].dt_txt);
                lbl_Conditions3.Text  = string.Format("{0}", forcast.list[3].weather[0].main);        //oro būsena
                lbl_Description3.Text = string.Format("{0}", forcast.list[3].weather[0].description); //oro aprašimas
                lbl_daysTemp3.Text    = string.Format("{0} \u00B0" + "C", forcast.list[3].main.temp); //oro temperatūra
                lbl_WindSpeed3.Text   = string.Format("{0} km/h", forcast.list[3].wind.speed);        //vėjo greitis



                lbl_Days4.Text        = string.Format("{0}", forcast.list[6].dt_txt);
                lbl_Conditions4.Text  = string.Format("{0}", forcast.list[6].weather[0].main);
                lbl_Description4.Text = string.Format("{0}", forcast.list[6].weather[0].description);
                lbl_daysTemp4.Text    = string.Format("{0} \u00B0" + "C", forcast.list[6].main.temp);
                lbl_WindSpeed4.Text   = string.Format("{0} km/h", forcast.list[6].wind.speed);

                lbl_Days5.Text        = string.Format("{0}", forcast.list[9].dt_txt);
                lbl_Conditions5.Text  = string.Format("{0}", forcast.list[9].weather[0].main);
                lbl_Description5.Text = string.Format("{0}", forcast.list[9].weather[0].description);
                lbl_daysTemp5.Text    = string.Format("{0} \u00B0" + "C", forcast.list[9].main.temp);
                lbl_WindSpeed5.Text   = string.Format("{0} km/h", forcast.list[9].wind.speed);


                string        connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\serge\source\repos\BaigiamasisDarbas_Orai_Sergej\BaigiamasisDarbas_Orai_Sergej\City.mdf;Integrated Security=True";
                SqlConnection sql     = new SqlConnection(connectionString);
                string        querry  = "SELECT TOP 1 * FROM IconsTable";
                SqlCommand    command = new SqlCommand(querry, sql);
                sql.Open();
                SqlDataReader takeIcon = command.ExecuteReader();
                while (takeIcon.Read())
                {
                    IconsTable iconsTable = new IconsTable();
                    iconsTable.Icons = takeIcon["Icons"].ToString();
                    IconChangeVar    = iconsTable.Icons;
                }
                sql.Close();


                if (IconChangeVar == null)
                {
                    string iconNr2 = forcast.list[0].weather[0].icon;

                    string url2 = string.Format("http://openweathermap.org/img/wn/{0}@2x.png", iconNr2);

                    WebRequest request2 = WebRequest.Create(url2);
                    using (var response2 = request2.GetResponse())
                    {
                        using (var str2 = response2.GetResponseStream())
                        {
                            pictureBox2.Image = Bitmap.FromStream(str2);
                        }
                    }

                    string iconNr3 = forcast.list[3].weather[0].icon;

                    string url3 = string.Format("http://openweathermap.org/img/wn/{0}@2x.png", iconNr3);

                    WebRequest request3 = WebRequest.Create(url3);
                    using (var response3 = request3.GetResponse())
                    {
                        using (var str3 = response3.GetResponseStream())
                        {
                            pictureBox3.Image = Bitmap.FromStream(str3);
                        }
                    }

                    string iconNr4 = forcast.list[6].weather[0].icon;

                    string url4 = string.Format("http://openweathermap.org/img/wn/{0}@2x.png", iconNr4);

                    WebRequest request4 = WebRequest.Create(url4);
                    using (var response4 = request4.GetResponse())
                    {
                        using (var str4 = response4.GetResponseStream())
                        {
                            pictureBox4.Image = Bitmap.FromStream(str4);
                        }
                    }

                    string iconNr5 = forcast.list[9].weather[0].icon;

                    string url5 = string.Format("http://openweathermap.org/img/wn/{0}@2x.png", iconNr5);

                    WebRequest request5 = WebRequest.Create(url5);
                    using (var response5 = request5.GetResponse())
                    {
                        using (var str5 = response5.GetResponseStream())
                        {
                            pictureBox5.Image = Bitmap.FromStream(str5);
                        }
                    }
                }
                else
                {
                    ChangeIcon2();
                    ChangeIcon3();
                    ChangeIcon4();
                    ChangeIcon5();
                }
            }
        }