Example #1
0
        private void label48_Click(object sender, EventArgs e)
        {
            images = DataHendler.GetArrayImg(owForecast, 9);
            Size old   = new Size(739, 622);
            Size s_new = new Size(1360, 622);


            if (this.Size == old)
            {
                this.Size       = s_new;
                label2.Location = new System.Drawing.Point(1326, -3);
                label3.Location = new System.Drawing.Point(1294, -3);
                if (chart_builded == false || city_old != city)
                {
                    chart1.Series["Погода"].Points.Clear();
                    for (int i = 0, j = 0; j < 9; i++, j++)
                    {
                        chart1.Series["Погода"].Points.AddXY(data[j], weather[i]);
                    }
                    chart_builded = true;
                    city_old      = city;
                    ptBoxa1.Image = images[0];
                    ptBoxa2.Image = images[1];
                    ptBoxa3.Image = images[2];
                    ptBoxa4.Image = images[3];
                    ptBoxa5.Image = images[4];
                    ptBoxa6.Image = images[5];
                    ptBoxa7.Image = images[6];
                    ptBoxa8.Image = images[7];
                    ptBoxa9.Image = images[8];
                }
                //this.Show();
            }
            else
            {
                this.Size       = old;
                label2.Location = new System.Drawing.Point(703, -3);
                label3.Location = new System.Drawing.Point(671, -3);
                //this.Show();
            }
        }
Example #2
0
        /// <summary>
        ///  Заполняет данные про погоду по заданому городу
        /// </summary>
        /// <param name="town">Место с которого будет взята погода</param>
        private void ShowInf(string town)
        {
            if (UrlHandler.UrlCheck(todayUrlPt1 + town + todayUrlPt3) && UrlHandler.UrlCheck(forecastUrlPt1 + town + forecastUrlPt3))
            {
                GetInfoFromUrl.SetInf(todayUrlPt1 + town + todayUrlPt3, out owCurrent);

                GetInfoFromUrl.SetInf(forecastUrlPt1 + town + forecastUrlPt3, out owForecast);

                this.Invoke(new Action(() => {
                    images = DataHendler.GetArrayImg(owForecast, 9);

                    weather = DataHendler.GetArrayTemp(owForecast, 9); //Масив погоды

                    data = DataHendler.GetArrayData(owForecast, 9);    //Маисв даты

                    if (chart_builded == false || city_old != city)
                    {
                        chart1.Series["Погода"].Points.Clear();
                        for (int i = 0, j = 0; j < 9; i++, j++)
                        {
                            chart1.Series["Погода"].Points.AddXY(data[j], weather[i]);
                        }
                        chart_builded = true;
                        city_old      = city;
                        ptBoxa1.Image = images[0];
                        ptBoxa2.Image = images[1];
                        ptBoxa3.Image = images[2];
                        ptBoxa4.Image = images[3];
                        ptBoxa5.Image = images[4];
                        ptBoxa6.Image = images[5];
                        ptBoxa7.Image = images[6];
                        ptBoxa8.Image = images[7];
                        ptBoxa9.Image = images[8];
                    }

                    pictureBox1.Image = owCurrent.weather[0].Icon;

                    label22.Text = owCurrent.weather[0].description;

                    label21.Text = owCurrent.main.temp.ToString("0.##") + "℃";

                    label23.Text = owCurrent.wind.speed.ToString();

                    label32.Text = owCurrent.main.humidity.ToString();

                    label24.Text = ((int)owCurrent.main.pressure).ToString();

                    label18.Text = owCurrent.name.ToString();


                    label61.Text = DataHendler.SplitDataData(owForecast.list[0].dt_txt);


                    label49.Text = DataHendler.SplitDataData(owForecast.list[8].dt_txt);


                    label33.Text = DataHendler.SplitDataData(owForecast.list[16].dt_txt);


                    label43.Text = DataHendler.SplitDataData(owForecast.list[24].dt_txt);

                    label28.Text = owForecast.list[8].wind.speed.ToString();

                    label58.Text = owForecast.list[8].main.humidity.ToString();

                    label30.Text = ((int)owForecast.list[8].main.pressure).ToString();

                    label45.Text = (GetMinTemp(owForecast, 8, 17)).ToString("0.##") + "℃";

                    label26.Text = (GetMaxTemp(owForecast, 8, 17)).ToString("0.##") + "℃";

                    label40.Text = owForecast.list[16].wind.speed.ToString();

                    label59.Text = owForecast.list[16].main.humidity.ToString();

                    label37.Text = ((int)owForecast.list[16].main.pressure).ToString();

                    label36.Text = (GetMinTemp(owForecast, 16, 25)).ToString("0.##") + "℃";

                    label41.Text = (GetMaxTemp(owForecast, 16, 25)).ToString("0.##") + "℃";

                    label55.Text = owForecast.list[24].wind.speed.ToString();

                    label60.Text = owForecast.list[24].main.humidity.ToString();

                    label52.Text = ((int)owForecast.list[24].main.pressure).ToString();

                    label51.Text = (GetMinTemp(owForecast, 24, 33)).ToString("0.##") + "℃";

                    label56.Text = (GetMaxTemp(owForecast, 24, 33)).ToString("0.##") + "℃";
                }));
            }
            else
            {
                MessageBox.Show($"Погода не найдена, проверте правильность данных\nили подключение к интернету", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #3
0
        private async void Main_UI_Load(object sender, EventArgs e)
        {
            labelforselect.Select();
            myHttpWebRequest = (HttpWebRequest)WebRequest.Create(urlForStart);

            try
            {
                await Task.Run(() => GetInfoFromUrl.SetInf(testUrl, out owForecast));

                myHttpWebResponse = (HttpWebResponse)await myHttpWebRequest.GetResponseAsync();

                string answer = string.Empty;

                using (Stream s = myHttpWebResponse.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(s))
                    {
                        answer = await reader.ReadToEndAsync();
                    }
                }

                myHttpWebResponse.Close();

                OpenWeather.OpenWeather ow = JsonConvert.DeserializeObject <OpenWeather.OpenWeather>(answer);

                weather = DataHendler.GetArrayTemp(owForecast, 9); // - масив для температуры

                data = DataHendler.GetArrayData(owForecast, 9);    // - масив для времени

                pictureBox1.Image = ow.weather[0].Icon;

                label22.Text = ow.weather[0].description;

                label21.Text = ow.main.temp.ToString("0.##") + "℃";

                label23.Text = ow.wind.speed.ToString();

                label32.Text = ow.main.humidity.ToString();

                label24.Text = ((int)ow.main.pressure).ToString();

                label18.Text = ow.name.ToString();


                label61.Text = DataHendler.SplitDataData(owForecast.list[0].dt_txt);


                label49.Text = DataHendler.SplitDataData(owForecast.list[8].dt_txt);


                label33.Text = DataHendler.SplitDataData(owForecast.list[16].dt_txt);


                label43.Text = DataHendler.SplitDataData(owForecast.list[24].dt_txt);

                label28.Text = owForecast.list[8].wind.speed.ToString();

                label58.Text = owForecast.list[8].main.humidity.ToString();

                label30.Text = ((int)owForecast.list[8].main.pressure).ToString();

                label45.Text = (GetMinTemp(owForecast, 8, 17)).ToString("0.##") + "℃";

                label26.Text = (GetMaxTemp(owForecast, 8, 17)).ToString("0.##") + "℃";

                label40.Text = owForecast.list[16].wind.speed.ToString();

                label59.Text = owForecast.list[16].main.humidity.ToString();

                label37.Text = ((int)owForecast.list[16].main.pressure).ToString();

                label36.Text = (GetMinTemp(owForecast, 16, 25)).ToString("0.##") + "℃";

                label41.Text = (GetMaxTemp(owForecast, 16, 25)).ToString("0.##") + "℃";

                label55.Text = owForecast.list[24].wind.speed.ToString();

                label60.Text = owForecast.list[24].main.humidity.ToString();

                label52.Text = ((int)owForecast.list[24].main.pressure).ToString();

                label51.Text = (GetMinTemp(owForecast, 24, 33)).ToString("0.##") + "℃";

                label56.Text = (GetMaxTemp(owForecast, 24, 33)).ToString("0.##") + "℃";
            }
            catch (WebException ex)
            {
                MessageBox.Show($"Погода не найдена, проверте правильность данных.\n{ex.Status}", "Увага!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Ошибка. Код ошибки: \n{ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }