Esempio n. 1
0
        public async void loadAPI(string searchInput)
        {
            checkFavourite(searchInput);

            BasicWeatherRecord  bwr  = null;
            BasicWeatherRecord  bwrT = null;
            DetailWeatherRecord dwr  = null;

            if (searchInput.Equals(""))
            {
                bwrT = await WeatherProcess.LoadBasicWeatherRecordCoord();

                bwr = await WeatherProcess.LoadBasicWeatherRecordCoord();

                dwr = await WeatherProcess.LoadDetailWeatherRecordCoord();
            }
            else
            {
                bwr = await WeatherProcess.LoadBasicWeatherRecord(searchInput);

                dwr = await WeatherProcess.LoadDetailWeatherRecord(searchInput);
            }



            if (bwr == null || dwr == null)
            {
                return;
            }

            cityName.Content = dwr.city.Name + ", " + dwr.city.Country;
            currentForecastTemperature.Content = Convert.ToInt32(bwr.Main.Temp) + "°C";
            currentForecastStatus.Content      = bwr.Weathers[0].Description;
            currentForecastInfo.Content        = "Last update at " + DateTime.Now.ToString("HH:mm:ss");

            currentForecastLogo.Source = getImage(bwr.Weathers[0].Icon);

            List <PerHourRecord> recordsDay2 = new List <PerHourRecord>();
            List <PerHourRecord> recordsDay3 = new List <PerHourRecord>();
            List <PerHourRecord> recordsDay4 = new List <PerHourRecord>();
            List <PerHourRecord> recordsDay5 = new List <PerHourRecord>();

            string dateDay2 = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
            string dateDay3 = DateTime.Now.AddDays(2).ToString("yyyy-MM-dd");
            string dateDay4 = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd");
            string dateDay5 = DateTime.Now.AddDays(4).ToString("yyyy-MM-dd");


            foreach (PerHourRecord phr in dwr.Records)
            {
                if (phr.time.StartsWith(dateDay2))
                {
                    recordsDay2.Add(phr);
                }
                else if (phr.time.StartsWith(dateDay3))
                {
                    recordsDay3.Add(phr);
                }
                else if (phr.time.StartsWith(dateDay4))
                {
                    recordsDay4.Add(phr);
                }
                else if (phr.time.StartsWith(dateDay5))
                {
                    recordsDay5.Add(phr);
                }
            }


            Day1Date.Content        = DateTime.Today.ToString("dddd").Substring(0, 3) + " " + DateTime.Today.ToString("dd");
            Day1Logo.Source         = getImage(bwr.Weathers[0].Icon);
            Day1Max.Content         = Convert.ToInt32(bwr.Main.Temp_max) + "°C";
            Day1Min.Content         = Convert.ToInt32(bwr.Main.Temp_min) + "°C";
            Day1Description.Content = bwr.Weathers[0].Main;

            List <string> res2 = getMinAndMaxTemp(recordsDay2);

            Day2Date.Content        = DateTime.Today.AddDays(1).ToString("dddd").Substring(0, 3) + " " + DateTime.Today.AddDays(1).ToString("dd");
            Day2Max.Content         = Convert.ToInt32(res2[1]) + "°C";
            Day2Min.Content         = Convert.ToInt32(res2[0]) + "°C";
            Day2Description.Content = res2[2];
            Day2Logo.Source         = getImage(res2[3]);


            List <string> res3 = getMinAndMaxTemp(recordsDay3);

            Day3Date.Content        = DateTime.Today.AddDays(2).ToString("dddd").Substring(0, 3) + " " + DateTime.Today.AddDays(2).ToString("dd");
            Day3Max.Content         = Convert.ToInt32(res3[1]) + "°C";
            Day3Min.Content         = Convert.ToInt32(res3[0]) + "°C";
            Day3Description.Content = res3[2];
            Day3Logo.Source         = getImage(res3[3]);


            List <string> res4 = getMinAndMaxTemp(recordsDay4);

            Day4Date.Content        = DateTime.Today.AddDays(3).ToString("dddd").Substring(0, 3) + " " + DateTime.Today.AddDays(3).ToString("dd");
            Day4Max.Content         = Convert.ToInt32(res4[1]) + "°C";
            Day4Min.Content         = Convert.ToInt32(res4[0]) + "°C";
            Day4Description.Content = res4[2];
            Day4Logo.Source         = getImage(res4[3]);


            List <string> res5 = getMinAndMaxTemp(recordsDay5);

            Day5Date.Content        = DateTime.Today.AddDays(4).ToString("dddd").Substring(0, 3) + " " + DateTime.Today.AddDays(4).ToString("dd");
            Day5Max.Content         = Convert.ToInt32(res5[1]) + "°C";
            Day5Min.Content         = Convert.ToInt32(res5[0]) + "°C";
            Day5Description.Content = res5[2];
            Day5Logo.Source         = getImage(res5[3]);



            Detail1Temp.Content        = Convert.ToInt32(dwr.Records[0].Main.Temp) + "°C";
            Detail1Description.Content = dwr.Records[0].Weathers[0].Main;
            Detail1Time.Content        = dwr.Records[0].time.Substring(dwr.Records[0].time.Length - 8, 5);
            Detail1Logo.Source         = getImage(dwr.Records[0].Weathers[0].Icon);


            Detail2Temp.Content        = Convert.ToInt32(dwr.Records[1].Main.Temp) + "°C";
            Detail2Description.Content = dwr.Records[1].Weathers[0].Main;
            Detail2Time.Content        = dwr.Records[1].time.Substring(dwr.Records[1].time.Length - 8, 5);
            Detail2Logo.Source         = getImage(dwr.Records[1].Weathers[0].Icon);


            Detail3Temp.Content        = Convert.ToInt32(dwr.Records[2].Main.Temp) + "°C";
            Detail3Description.Content = dwr.Records[2].Weathers[0].Main;
            Detail3Time.Content        = dwr.Records[2].time.Substring(dwr.Records[2].time.Length - 8, 5);
            Detail3Logo.Source         = getImage(dwr.Records[2].Weathers[0].Icon);


            Detail4Temp.Content        = Convert.ToInt32(dwr.Records[3].Main.Temp) + "°C";
            Detail4Description.Content = dwr.Records[3].Weathers[0].Main;
            Detail4Time.Content        = dwr.Records[3].time.Substring(dwr.Records[3].time.Length - 8, 5);
            Detail4Logo.Source         = getImage(dwr.Records[3].Weathers[0].Icon);


            Detail5Temp.Content        = Convert.ToInt32(dwr.Records[4].Main.Temp) + "°C";
            Detail5Description.Content = dwr.Records[4].Weathers[0].Main;
            Detail5Time.Content        = dwr.Records[4].time.Substring(dwr.Records[4].time.Length - 8, 5);
            Detail5Logo.Source         = getImage(dwr.Records[4].Weathers[0].Icon);


            Detail6Temp.Content        = Convert.ToInt32(dwr.Records[5].Main.Temp) + "°C";
            Detail6Description.Content = dwr.Records[5].Weathers[0].Main;
            Detail6Time.Content        = dwr.Records[5].time.Substring(dwr.Records[5].time.Length - 8, 5);
            Detail6Logo.Source         = getImage(dwr.Records[5].Weathers[0].Icon);


            Detail7Temp.Content        = Convert.ToInt32(dwr.Records[6].Main.Temp) + "°C";
            Detail7Description.Content = dwr.Records[6].Weathers[0].Main;
            Detail7Time.Content        = dwr.Records[6].time.Substring(dwr.Records[6].time.Length - 8, 5);
            Detail7Logo.Source         = getImage(dwr.Records[6].Weathers[0].Icon);


            Detail8Temp.Content        = Convert.ToInt32(dwr.Records[7].Main.Temp) + "°C";
            Detail8Description.Content = dwr.Records[7].Weathers[0].Main;
            Detail8Time.Content        = dwr.Records[7].time.Substring(dwr.Records[7].time.Length - 8, 5);
            Detail8Logo.Source         = getImage(dwr.Records[7].Weathers[0].Icon);

            if (searchInput.Equals(""))
            {
                string        currentLocation = cityName.Content.ToString();
                List <string> currentCityList = currentLocation.Split(',').ToList <string>();
                string        currentCity     = currentCityList[0];
                checkFavourite(currentCity);
            }
        }
        public async void loadBookmarkAPI()
        {
            Bookmark bookmark = new Bookmark();



            foreach (BookmarkData bd in bookmark.getHistory())
            {
                MyGrid LabelGrid = new MyGrid();
                LabelGrid.CityName          = bd.CityName;
                LabelGrid.Background        = getLightDailyColor();
                LabelGrid.PreviewMouseDown += LabelGrid_PreviewMouseDown;
                LabelGrid.MouseEnter       += LabelGrid_MouseEnter;
                LabelGrid.MouseLeave       += LabelGrid_MouseLeave;
                LabelGrid.Margin            = new Thickness(20, 20, 20, 20);
                LabelGrid.Height            = 130;
                LabelGrid.Width             = 200;
                LabelGrid.ColumnDefinitions.Clear();
                LabelGrid.RowDefinitions.Clear();

                LabelGrid.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(2, GridUnitType.Star)
                });
                LabelGrid.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(4, GridUnitType.Star)
                });
                LabelGrid.RowDefinitions.Clear();
                BasicWeatherRecord bwr = await WeatherProcess.LoadBasicWeatherRecord(bd.CityName);

                LabelGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(4, GridUnitType.Star)
                });
                LabelGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(4, GridUnitType.Star)
                });
                LabelGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(2.5, GridUnitType.Star)
                });
                LabelGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(2.5, GridUnitType.Star)
                });


                Label cityName = new Label();
                cityName.Content             = bd.CityName;
                cityName.FontSize            = 22;
                cityName.HorizontalAlignment = HorizontalAlignment.Center;
                cityName.Foreground          = new SolidColorBrush(Colors.White);
                MyGrid.SetRow(cityName, 0);
                MyGrid.SetColumnSpan(cityName, 2);
                LabelGrid.Children.Add(cityName);


                Label currTemp = new Label();
                currTemp.Content    = Convert.ToInt32(bwr.Main.Temp) + "°C";
                currTemp.FontSize   = 22;
                currTemp.Foreground = new SolidColorBrush(Colors.White);
                MyGrid.SetRow(currTemp, 1);
                MyGrid.SetColumnSpan(currTemp, 2);
                currTemp.HorizontalAlignment = HorizontalAlignment.Center;
                LabelGrid.Children.Add(currTemp);

                Label maxTemp = new Label();
                maxTemp.Content = "Max: " + Convert.ToInt32(bwr.Main.Temp_max) + "°C";
                //maxTemp.FontSize = 15;
                maxTemp.Foreground = new SolidColorBrush(Colors.White);
                MyGrid.SetRow(maxTemp, 2);
                MyGrid.SetColumn(maxTemp, 1);
                maxTemp.HorizontalAlignment = HorizontalAlignment.Right;
                LabelGrid.Children.Add(maxTemp);

                Label minTemp = new Label();
                minTemp.Content = "Min: " + Convert.ToInt32(bwr.Main.Temp_min) + "°C";
                //minTemp.FontSize = 15;
                minTemp.HorizontalAlignment = HorizontalAlignment.Right;
                minTemp.Foreground          = new SolidColorBrush(Colors.White);
                MyGrid.SetRow(minTemp, 3);
                MyGrid.SetColumn(minTemp, 1);
                LabelGrid.Children.Add(minTemp);

                Label description = new Label();
                description.Content    = bwr.Weathers[0].Main;
                description.Foreground = new SolidColorBrush(Colors.White);
                MyGrid.SetRow(description, 3);
                MyGrid.SetColumn(description, 0);
                LabelGrid.Children.Add(description);

                Image image = new Image();
                image.Source = getImage(bwr.Weathers[0].Icon);
                image.HorizontalAlignment = HorizontalAlignment.Left;
                MyGrid.SetColumn(image, 0);
                MyGrid.SetRow(image, 2);
                LabelGrid.Children.Add(image);
                //I want to creatre the Seperate coloum and row to  display KEY
                // VALUE Pair distinctly
                bookmarkList.Children.Add(LabelGrid);
            }
        }